Mysql 有人能解释一下这个sql查询是如何工作的吗。分批订货
**问题--为每个客户返回客户ID和地区 -按区域对输出中的行进行排序 -在非NULL值之后最后排序NULLMysql 有人能解释一下这个sql查询是如何工作的吗。分批订货,mysql,sql-order-by,Mysql,Sql Order By,**问题--为每个客户返回客户ID和地区 -按区域对输出中的行进行排序 -在非NULL值之后最后排序NULL select custid , region from sales.Customers order by case when region is null then 1 else 0 end , region 将查询更改为: select custid , region , case when region is null the
select custid
, region
from sales.Customers
order
by case when region is null then 1 else 0 end
, region
将查询更改为:
select custid
, region
, case when region is null then 1 else 0 end sorter
from sales.Customers
现在您可以看到它在做什么了吗?当区域为空时,则1 else 0 end在区域为空时产生1,否则产生0。由于1>0,将在非null值之后排序null。如果这是你不明白的。否则,你需要更精确地解释你实际上不理解的东西。