Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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
如果列=X,则MySQL按DESC排序,否则为ASC_Mysql_Sql Order By - Fatal编程技术网

如果列=X,则MySQL按DESC排序,否则为ASC

如果列=X,则MySQL按DESC排序,否则为ASC,mysql,sql-order-by,Mysql,Sql Order By,如果finished=1,则如何按开始日期说明进行订单查询,否则按开始日期说明进行订单查询。现在看来是这样的: SELECT game_id, event_id, start_date, best_of, home_team_id, away_team_id, home_value, away_value, home_result, away_result, stream_url, st

如果
finished
=1,则如何按开始日期说明进行订单查询,否则按开始日期说明进行订单查询。现在看来是这样的:

SELECT game_id, 
    event_id, 
    start_date, 
    best_of, 
    home_team_id, 
    away_team_id, 
    home_value, 
    away_value, 
    home_result, 
    away_result, 
    stream_url, 
    stats_url, 
    comments, 
    finished 
FROM betting_games 
ORDER BY finished ASC, 
    start_date ASC 
LIMIT 5
这里有一个方法:

SELECT *
FROM betting_games
ORDER BY finished ASC, 
         CASE 
            WHEN finished =  1 THEN - 1 * UNIX_TIMESTAMP(start_date)
            ELSE UNIX_TIMESTAMP(start_date)
         END ASC 
不能从
大小写
表达式返回
DESC
ASC
。使用
UNIX\u TIMESTAMP
,将日期字段
start\u date
转换为整数,可用于按降序存储(一旦取反)

这里有一种方法:

SELECT *
FROM betting_games
ORDER BY finished ASC, 
         CASE 
            WHEN finished =  1 THEN - 1 * UNIX_TIMESTAMP(start_date)
            ELSE UNIX_TIMESTAMP(start_date)
         END ASC 
不能从
大小写
表达式返回
DESC
ASC
。使用
UNIX\u TIMESTAMP
,将日期字段
start\u date
转换为整数,可用于按降序存储(一旦取反)