📜 sql order by 置顶
先讲一下需求:
我有一张表
id | name |
---|---|
1 | xxx |
2 | yyy |
... | ... |
现在我需要把 id 为 222
和 333
的数据置顶查询出来
select * from 表
ORDER BY
case
when id = 222 THEN 0
when id = 333 THEN 0
else 1
end asc,
id asc
;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
通过 case 可以实现