我有一张桌子
表用户
Id Name status
1 Jhon Approved
2 Endy Decline
3 Ally In Review
我必须显示所有用户的列表,并仅对那些未经批准的行进行排序。
我的代码在
下面(select name from user where status<>'Approved' order by status asc)
UNION
(select name from user where status='Approved')
我总是在ASC
和DESC
Id Name status
3 Ally In Review
2 Endy Decline
1 Jhon Approved
name
的订单也应该是相同的结果。
(select name from user where status<>'Approved' order by name asc)
UNION
(select name from user where status='Approved')
Id Name status
3 Ally In Review
2 Endy Decline
1 Jhon Approved
请帮帮我。非常感谢您的帮助。
答案 0 :(得分:1)
您可以将case when
用于order by
select * from User
order by
case when status <> 'Approved' then 0 else 1 end ,status;
答案 1 :(得分:0)
尝试使用union all更改union,它至少在oracle
中起作用select * from
(select * from t1 where status <> 'Approved' order by status asc)
union all
select * from
(select * from t1 where status = 'Approved' )
输出:
ID|NAME|STATUS
2|Endy|Declined
3|Ally|In Review
1|John|Approved
希望它可以帮到你。 :)
答案 2 :(得分:0)
感谢您的回复。我得到了解决方案
(select * from
(select * from user where status <> 'Approved' order by status asc) a)
union
(select * from t1 where status = 'Approved' )