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

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;这样子是你要的效果咩,如果不符合我再改

迷茫

(select from user where status=1 order by id desc) union all (select from user where status=0 order by register_time asc)

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!