MySQL查询用户表中所有记录,按ID降序排序,如果用户状态为0(未激活),则注册时间升序,排在结果最后,这个SQL.该怎么写呢
ringa_lee
ringa_lee 2017-04-17 15:55:51
0
3
709

MySQL查询用户表中所有记录,按ID降序排序,如果用户状态为0(未激活),则注册时间升序,排在结果最后,这个SQL.该怎么写呢?

ringa_lee
ringa_lee

ringa_lee

全部回覆(3)
Ty80

假設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 排序)

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!