更新时间:2023-01-17 19:11:29
您几乎可以使用 case
在 order by
中进行任何排序.首先是 null
列,然后是空字符串,其余的列在 col1 和 col3 上:
You can do almost any sort using a case
in an order by
. Here's the null
columns first, then the empty strings, and the rest ordered on col1 and col3:
select *
from YourTable
order by
case when col1 is null then 1
when col1 = '' then 2
else 3
end
, col2
, col3 desc