mysql 我想在使用SELECT语句进行查询时增加一列,列值应如下所示,

2nc8po8w  于 2023-02-28  发布在  Mysql
关注(0)|答案(1)|浏览(125)
nameclassmarksnew_column##Heading ##
jim1501
jim2501
jim3401
tom4302
tom3702
tom2802
tom1702
tom5802

The name column changes every time I query but a similar name will come each time(like 5 Herry, 6 Lucy).
So I want a new_column where first similar names are assigned 1 and next similar names will be assigned 2 and so on.

ljsrvy3e

ljsrvy3e1#

您正在查找dense_rank窗口函数:

SELECT   *, DENSE_RANK() OVER (ORDER BY name) AS new_column
FROM     mytable
ORDER BY name

相关问题