84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
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)