PostgreSQL排序把null值排在后面

null排在有值的行前面还是后面通过语法来指定

--null值在前
select * from tablename order by id nulls first;
 
 
--null值在后
select * from tablename order by id nulls last;
 
 
--null在前配合desc使用
select * from tablename order by id desc nulls first;
 
 
--null在后配合desc使用
select * from tablename order by id desc nulls last;
 
 
举例:
null值在后,先按照count1降序排列,count1相同再按照count2降序排列
 
order by count1 desc nulls last, count2  desc nulls last;

要是还有不太明白的地方请留言,评论必回
要是对我的文章感兴趣的话,关注一下吧,谢谢!

上一篇:PostgreSQL 修改id的自增起始数

下一篇:FTPClient文件上传问题