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

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 排序) union all(从状态 = 0 的用户中按 register_time asc 选择

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!