Row_number 语法错误 (Wordpress)

Row_number syntax error (Wordpress)

我需要帮助。我是 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 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ORDER BY id) AS player_num, CONCAT(name,' ',last_name) AS player_name, date_of_' at line 1 MySQL is in WP

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

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

这里还有一个关于 OVER 子句的视频。

Over Clause in SQL

考虑对 return 行号使用条件计数聚合子查询。下面按姓氏分配递增的行号:

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