mariadb查询问题(order by忽略)

ulmd4ohb  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(301)

我有一个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
mbjcgjjk

mbjcgjjk1#

这个 ORDER BY 需要移出一层。
这就是原因。mariadb现在正在遵守这个标准,即子选择是一组无序的行。也就是说,内心 ORDER BY 可以忽略。mariadb在过去的几个版本中都是这样做的;mysql也在最新版本中这样做。
在过去,mysql和mariadb盲目地做任何事情 ORDER BY 由用户请求。然后将结果按顺序输入到查询的下一阶段。
极限技巧
如果这不起作用,添加 LIMIT 99999999 之后 ORDER BY 在最里面 SELECT . 这将防止优化器忽略 ORDER BY ,而实际上没有做任何“限制”。

相关问题