如何在查询中使用MySQL ROW_NUMBER函数

问题描述 投票:1回答:1

我试图了解MySQL ROW_NUMBER()函数以及如何使用它为结果集中的每一行生成一个序列号。

到目前为止我尝试了什么:

SELECT *, 
ROLL_NUMBER() 
OVER(PARTITION BY examid ORDER BY examid) AS id 
from exam

当我运行此查询时,显示了一系列错误:

分析期间发现3个错误。

An alias was previously found. (near "id" at position 68)
An alias was expected. (near " " at position 67)
Unexpected token. (near "id" at position 68)

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 '(PARTITION BY examid ORDER BY examid) as id from exam LIMIT 0, 25' at line 1

我该怎么办呢?

谢谢。

mysql row-number windowing-functions
1个回答
0
投票

将我改为别的,因为select *语句将返回一个id,它将与我的(AS id)冲突

© www.soinside.com 2019 - 2024. All rights reserved.