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

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;

いいねを押す +0
阿神

select * from user order by id ASC , status ASC , register_time ASC;これはあなたが望む効果です。私に合わない場合は変更します

いいねを押す +0
迷茫

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

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!