Row_number语法错误(Wordpress)

时间:2015-12-01 18:44:11

标签: mysql sql window-functions

我需要帮助。我是SQL和Wordpress的初学者。

这是我的疑问。

SELECT ROW_NUMBER() OVER (ORDER BY id) AS player_num,
CONCAT(name,' ',last_name) AS player_name, date_of_birth, phone, email 
FROM barbara_players 
ORDER BY last_name ASC

显示语法错误。

  

#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便使用接近'(ORDER BY id)AS player_num,CONCAT(名称,'',last_name)AS player_name,date_of _&#39 ;在第1行,MySQL在WP中

我不知道为什么。我想我就像在教程中一样。是的,我在Wordpress工作。我想向我展示行数和其他提到的列。

2 个答案:

答案 0 :(得分:0)

试试这个 计算ROW_NUMBER()OVER(PARTITION BY id).....

以下是关于OVER子句的视频。

Over Clause in SQL

答案 1 :(得分:0)

考虑使用条件计数聚合子查询来返回行号。下面按姓氏指定增加的行号:

SELECT 
     (SELECT Count(*) 
     FROM barbara_players t2 
     WHERE t1.last_name >= t2.last_name) AS player_num, 
     CONCAT(t1.name,' ', t1.last_name) AS player_name, 
     t1.date_of_birth, t1.phone, t1.email 
FROM barbara_players t1
ORDER BY t1.last_name ASC