sql 语句中,一个表有两个字段,status和date,如何查询status是2和6的排在前面,剩下的按照date倒序排序

求指教啊~
2024-11-24 04:07:29
推荐回答(3个)
回答1:

select case status when 2 then 2 when 6 then 6 else 7 end statusOrder,status,date from 表名 order by 1,2desc

也就是将status操作后给个伪列进行重排

回答2:

select status,date from 表 where status=2 or status=6 order by status
UNION select status,date from 表 where status<>2 and status<>6 order by date;

回答3:

(select* from tb_1 where status in(2,6) order by date)
union
(select * from tb_1 where status not in(2,6) order by date)