MySQL 5.6.39中的等效语句是什么?

时间:2018-07-25 00:24:52

标签: mysql mariadb

我最近转移到了具有MySQL 5.6.39而不是MariaDB 10.x的共享主机,我想知道与MySQL中以下MariaDB语句等效吗?

SELECT rank,
       total
FROM
  (SELECT ROW_NUMBER() OVER (
                             ORDER BY `prestige` DESC, `xp` DESC) AS rank,

     (SELECT COUNT(*)
      FROM Modular_LS) AS total,
                            steamid
   FROM Modular_LS) sub
WHERE sub.steamid = '%s'

我已经做到了这一点,但是现在我被困住了

SELECT rank, total FROM
                        (SELECT @rank := @rank +1 as rank FROM Modular_LS,
                        (SELECT COUNT(*) FROM Modular_LS) AS total, steamid FROM Modular_LS) sub,
                        (SELECT @rank := 0) r ORDER BY `prestige` DESC, `xp` DESC) t;

表结构包含列Steamid,xp,信誉

我的目标是按声望先降序,然后xp降序排列,以类似的顺序进行排名,然后使用WHERE查询来查找特定玩家的排名。其输出包含排名(位置)和总数(记录总数)

2 个答案:

答案 0 :(得分:0)

Maybe this will get you started:

SELECT  @rank := IF(player_id = @prev, @rank + 1, 1), @prev := player_id
    FROM ( SELECT  @rank := 1, @prev = 0 ) AS init
    JOIN ( SELECT  player_id
               FROM  Modular_LS
               ORDER BY  prestige DESC, SP DESC 
         ) AS x ;

答案 1 :(得分:0)

几个小时后,这就是我想出的解决问题的方法。

SELECT
        sub.rank
        ,sub.total
    FROM
        (
            SELECT
                    t.id
                    ,t.steamid
                    ,@rownum : = @rownum + 1 AS rank
                    ,(
                        SELECT
                                COUNT (*)
                            FROM
                                Modular_LS
                    ) AS total
                FROM
                    Modular_LS t JOIN (
                        SELECT
                                @rownum : = 0
                    ) r
                ORDER BY
                    t.prestige DESC
                    ,t.xp DESC
        ) sub
    WHERE
        sub.steamid = '%s'