如何对具有多列的表进行排序,其中排序是按第一列的字母顺序排列,但第二列中具有空值或零的所有字母条目出现在最后。
排序前 表“用户”
username monies zip
jim 25 87888
allan 12 34333
adrian 0 97677
abel null 87888
will 4 88788
排序后 表“用户”
username monies zip
allan 12 34333
jim 25 87888
will 4 88788
abel null 87888
adrian 0 97677
我试过了,还是不行
SELECT
*
FROM
"user"
ORDER BY
name ASC,
monies nulls last
最佳答案
只需先对0
或null
进行排序,然后按用户名按字母顺序排序
order by case when monies = 0 or monies is null then 1 else 0 end, username
关于sql - Postgresql 按第一列排序,但第二列最后有空值或零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49314728/