结论
- 使用关键字
nulls first/last
即可处理。nulls first:
表示 null 值的记录将排在最前面(无论是 asc,还是 desc)nulls last:
表示 null 值的记录将排在最后面(无论是 asc,还是 desc)
SELECT t.* FROM scott.emp t ORDER BY t.comm NULLS FIRST; -- null 值在最前面
SELECT t.* FROM scott.emp t ORDER BY t.comm NULLS LAST; -- null 值在最后面
请注意
默认情况: null 默认为最大值
,即:
- asc(升序) 时,排在最后面
- desc(降序) 时,排在最前面