select * from dual order by age desc nulls last
select * from test order by age asc nulls first
sqlserver 认为 null 最小。
升序排列:null 值默认排在最前。
要想排后面,则:order by case when col is null then 1 else 0 end ,col
降序排列:null 值默认排在最后。
要想排在前面,则:order by case when col is null then 0 else 1 end , col desc
本文介绍了在SQL中如何处理NULL值的排序问题。包括在升序和降序排列时,如何让NULL值出现在结果集的开头或末尾。通过CASE WHEN语句实现灵活的排序需求。
6421

被折叠的 条评论
为什么被折叠?



