如果列=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
转换为整数,可用于按降序存储(一旦取反)