PostgreSQL排序把null值排在後面

playmaker發表於2020-11-12
--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;
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章