" Row_Number()over"语法错误

时间:2017-07-23 18:04:11

标签: mysql mariadb

我有以下表结构

CREATE TABLE `Modular_LS` (
`id` int(11) NOT NULL,
`steamid` varchar(32) NOT NULL,
`name` varchar(32) NOT NULL,
`xp` bigint(20) NOT NULL DEFAULT '0',
`prestige` tinyint(4) NOT NULL DEFAULT '0',
`creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

这是我试图执行的查询:

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'

但是我得到了

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(ORDER BY `prestige` DESC, `xp` DESC) AS rank, (SELECT COUNT(*) FROM Modular_LS)' at line 1

我做错了什么?这适用于以前安装的MariaDB,但现在它没有。

我也在MariaDB的第10.1.22节

1 个答案:

答案 0 :(得分:0)

MariaDB团队在10.2及更高版本中引入了窗口函数(例如ROW_NUMBER())。

你正在使用10.1。您之前的安装必须是更高版本。