gpt4 book ai didi

mysql - mysql中重复记录的编号

转载 作者:行者123 更新时间:2023-11-29 01:17:04 25 4
gpt4 key购买 nike

我有 Student 表,我想像这样更新 (sequence_No.) 字段:

ID        Name      age     sequence_No.
-- ----- --- ------------

1 sara 20 1

2 sara 20 2

3 sara 20 3

4 john 24 1

5 john 24 2

6 Hama 23 1

在 mysql 中哪个查询可以做到这一点?

谢谢你:)

最佳答案

SELECT 
ID,
Name,
age,
(
CASE Name
WHEN @curType
THEN @curRow := @curRow + 1
ELSE @curRow := 1 AND @curType := Name END
) + 1 AS sequence_No

FROM student, (SELECT @curRow := 0, @curType := '') r
ORDER BY ID,NAME;

SQL FIDDLE

关于mysql - mysql中重复记录的编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com