SQL 排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL 排序相关的知识,希望对你有一定的参考价值。

正常排序:

                order by 字段1,字段2,......字段n                       --所有字段按正序排序
                order by 字段1 desc,字段2,......字段n              --字段1按返序,其它按正序排序

特殊排序:

字段从小到大,但把0排到最后


order by (case 字段名 when ‘0‘ then ‘a‘ else 字段名 end)         --字段为字符时

order by (case 字段名 when 0 then 999999 else 字段名 end)  -- 字段为数字时

以上是关于SQL 排序的主要内容,如果未能解决你的问题,请参考以下文章