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;
(從狀態 = 1 的使用者中選擇 按 id desc 排序) 聯合所有(從狀態 = 0 的使用者中選擇 按 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;
這樣子是你要的效果咩,如果不符合我再改(從狀態 = 1 的使用者中選擇 按 id desc 排序) 聯合所有(從狀態 = 0 的使用者中選擇 按 register_time asc 排序)