【发布时间】:2021-05-03 22:49:29
【问题描述】:
**Question - -- 为每个客户返回客户 ID 和区域 -- 按区域对输出中的行进行排序 -- 让 NULL 排在最后(在非 NULL 值之后)
select custid
, region
from sales.Customers
order
by case when region is null then 1 else 0 end
, region
【问题讨论】:
-
case when region is null then 1 else 0 end当region为NULL时产生1,否则产生0。并且由于1>0将在非空值之后排序空。如果那是你不明白的。否则,您需要更准确地了解您实际上不了解的内容。
标签: mysql sql-order-by