84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
MySQL查询用户表中所有记录,按ID降序排序,如果用户状态为0(未激活),则注册时间升序,排在结果最后,这个SQL.该怎么写呢?
ringa_lee
假设status=1为激活,0未激活select *from user order by status desc,case status when 1 then id end desc,case status when 0 then created_at end asc;
select *from user order by status desc,case status when 1 then id end desc,case status when 0 then created_at end asc;
select * from user order by id ASC , status ASC , register_time ASC;这样子是你要的效果咩,如果不符合我再改
select * from user order by id ASC , status ASC , register_time ASC;
(select from user where status=1 order by id desc) union all (select from user where status=0 order by register_time asc)
假设status=1为激活,0未激活
select *from user order by status desc,case status when 1 then id end desc,case status when 0 then created_at end asc;
select * from user order by id ASC , status ASC , register_time ASC;
这样子是你要的效果咩,如果不符合我再改(select from user where status=1 order by id desc) union all (select from user where status=0 order by register_time asc)