我有一个MySQL查询运行正常,但我的托管proivder将我的数据库更改为MariaDB。查询本身工作正常,但我无法像在MySQL中那样使排序正常工作。
是否有某些语法已更改或不再可用?
SELECT
id,
name,
position,
player1,
player1_thru,
player1_to_par,
player2,
player2_thru,
player2_to_par,
player3,
player3_thru,
player3_to_par,
team_total,
IF (counter = 1, @rank:= placeholder, @rank) AS ranker
FROM(
SELECT
*,
@c := @c +1 AS placeholder,
IF(@a <> team_total, @b := @b := 1, @b :=0) AS counter,
@a := team_total
from(
SELECT
usopen_2018.id,
usopen_2018.position
, usopen_2018.name
, usopen_2018.player1
, player1_score.hole as player1_thru
, player1_score.to_par_s AS player1_to_par
, usopen_2018.player2
, player2_score.hole as player2_thru
, player2_score.to_par_s AS player2_to_par
, usopen_2018.player3
, player3_score.hole as player3_thru
, player3_score.to_par_s AS player3_to_par
, (player1_score.`to_par` + player2_score.`to_par` + player3_score.`to_par`) AS team_total
FROM usopen_2018
INNER JOIN leaderboard_A AS player1_score
ON player1_score.name = usopen_2018.player1
AND player1_score.tournament_name = 'U.S. Open'
AND player1_score.year = 2018
INNER JOIN leaderboard_A AS player2_score
ON player2_score.name = usopen_2018.player2
AND player2_score.tournament_name = 'U.S. Open'
AND player2_score.year = 2018
INNER JOIN leaderboard_A AS player3_score
ON player3_score.name = usopen_2018.player3
AND player3_score.tournament_name = 'U.S. Open'
AND player3_score.year = 2018
WHERE usopen_2018.cut = 0 AND usopen_2018.wd = 0
ORDER BY team_total, player1, player2, player3, name
)AS t
)AS FINAL
答案 0 :(得分:1)
SELECT cnt_stamp
FROM stm_events
ORDER BY FIELD(id, 3, 2, 1, 4) DESC;
需要移出一个级别。
这就是原因。 MariaDB 现在尊重标准,该标准表示子选择是无序行。也就是说,可以忽略内部ORDER BY
。 MariaDB在最后几个版本中已经这样做了; MySQL也在最新版本中这样做。
过去,MySQL和MariaDB盲目地做了用户请求的任何ORDER BY
。然后将结果仍按顺序提供给查询的下一阶段。
限制技巧
如果不起作用,请在最里面的ORDER BY
LIMIT 99999999
之后添加ORDER BY
。这应该使优化器不会忽略SELECT
,而实际上并没有做任何“限制”。