Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL按字段和案例排序,然后_Mysql_Sql_Mariadb_Sql Order By - Fatal编程技术网

MySQL按字段和案例排序,然后

MySQL按字段和案例排序,然后,mysql,sql,mariadb,sql-order-by,Mysql,Sql,Mariadb,Sql Order By,我试图按字段排序,并在语句结束时按大小写排序。 如果案例为ns,则日期应为ASC,时间应为ASC, 如果案例为pp,则日期应为ASC,时间应为ASC, 如果案例已完成,则日期应为DESC,时间应为ASC ns没有启动, pp延期, 完成了,完成了 我的代码: select * from matches where tournament_id = 12 order by FIELD(matches.status_key, 'ns', 'done', 'pp'), CASE WHEN matches

我试图按字段排序,并在语句结束时按大小写排序。 如果案例为ns,则日期应为ASC,时间应为ASC, 如果案例为pp,则日期应为ASC,时间应为ASC, 如果案例已完成,则日期应为DESC,时间应为ASC

ns没有启动, pp延期, 完成了,完成了

我的代码:

select * from matches
where tournament_id = 12
order by FIELD(matches.status_key, 'ns', 'done', 'pp'),
CASE WHEN matches.status_key = 'ns' THEN ('matches.date ASC, matches.time ASC') END,
CASE WHEN matches.status_key = 'pp' THEN ('matches.date ASC, matches.time ASC') END,
CASE WHEN matches.status_key = 'done' THEN ('matches.date DESC, matches.time ASC') END;
我猜这是一种错误的方法,我需要一些指导、建议和帮助来解决问题


谢谢你

我认为应该这样做:

order by 
    field(status_key, 'ns', 'done', 'pp'),
    case when status_key in ('ns', 'pp') then date,
    case when status_key = 'done'        then date desc,
    time