排序,数据中有正数,负数,0,我想先排序正数、负数,0统一全放在最后。
select * from table order by (case when 字段=0 then -999999 else 字段 end) desc
增加辅助列,为0的赋值-9999999,假如原值再E2,增加F2为辅助列,公式是,if(E2=0,'-999999',E2)
然后安辅助列排序
排序学习路径 https://help.fanruan.com/finereport/doc-view-4670.html
直接在sql中增加一个辅助列,把正数大类全部分类为1,负数为2,0为3
然后先按这个大类排序后,再对数字排序就行了
select t.* from (
select
*,
case when 数字字段>0 then 1
when 数字字段<0 then 2
else 0 end as order_fz
from 表名称
) t
order by t.order_fz,t.数字字段