ソートされた SQL
ステータス フィールドの逆順
ステータス = 1 の場合、時間フィールドは正の順序になり、ステータス = 0 の場合、時間フィールドは逆の順序になります
以下は、出力する必要がある結果です
id status time
5 1 50
6 1 51
1 0 99
10 0 1
select * from (select * from 表 where status = 1 order by time)aunion allselect * from (select * from 表 where status = o order by time desc)b
選択* テーブルからステータスによる順序 desc,if(status=1, 'time asc','time desc');
時間による順序 (status = 1 の場合、desc else asc end)
select * from (select * from 表 where status = 1 order by time)aunion allselect * from (select * from 表 where status = o order by time desc)b
select * from table order by status を続ける必要があります。 desc,if(status=1,'time asc',' time desc');
試してみましたか?
どのデータベースを使用していますか?
select * from table order by status desc,if(status=1,'time asc','time desc');
select * from tbl_name order by status=1 desc, time*if(status=1,1,-1)
時間順に並べます (status = 1 の場合は desc、それ以外の場合は asc 終了)
select * from tbl_name order by status=1 desc, time*if(status=1,1,-1)
order by time (case when status = 1 then desc else asc end)
select * from tbl_name order by status=1 desc, time*if(status=1,1,-1)
order by time (case when status = 1 then desc else asc end)
select * from (select * from 表 where status = 1 order by time)aunion allselect * from (select * from 表 where status = o order by time desc)b
SELECT * FROM (SELECT * FROM `table2` WHERE `status`=1 ORDER BY time ASC) aUNION ALLSELECT * FROM (SELECT * FROM `table2` WHERE `status`=0 ORDER BY time DESC) b
select * from (select * from 表 where status = 1 order by time)aunion allselect * from (select * from 表 where status = o order by time desc)b
SELECT * FROM (SELECT * FROM `table2` WHERE `status`=1 ORDER BY time ASC) aUNION ALLSELECT * FROM (SELECT * FROM `table2` WHERE `status`=0 ORDER BY time DESC) b