文章詳情頁(yè)
MySQL查詢用戶表中所有記錄,按ID降序排序,如果用戶狀態(tài)為0(未激活),則注冊(cè)時(shí)間升序,排在結(jié)果最后,這個(gè)SQL.該怎么寫呢
瀏覽:96日期:2022-06-17 10:10:58
問(wèn)題描述
MySQL查詢用戶表中所有記錄,按ID降序排序,如果用戶狀態(tài)為0(未激活),則注冊(cè)時(shí)間升序,排在結(jié)果最后,這個(gè)SQL.該怎么寫呢?
問(wèn)題解答
回答1:假設(shè)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;
回答2:select * from user order by id ASC , status ASC , register_time ASC;這樣子是你要的效果咩,如果不符合我再改
回答3:(select from user where status=1 order by id desc) union all (select from user where status=0 order by register_time asc)
排行榜

熱門標(biāo)簽