gpt4 book ai didi

mysql - 在 MY SQL 中运行 select 语句时如何生成自动增量值列?

转载 作者:行者123 更新时间:2023-11-29 12:44:50 25 4
gpt4 key购买 nike

如何显示当我运行以从表中查找重复值时,此时我想在带有自动增量值的 select 语句中添加新列

SELECT * FROM tutorials_tbl
WHERE Lscno IN (
SELECT Lscno
FROM tutorials_tbl
GROUP BY Lscno
HAVING COUNT(Lscno) > 1
)ORDER BY Lscno

ID Title LSCNo
10 titl_14 000000/06/3/1944
19 titl_13 000000/06/3/19
561 titl_1 000000/10/125/1955
671 titl_1 000000/10/125/1955
1765 titl_1 000000/06/65/1976
1834 titl_1 000000/06/65/1976
1909 titl_1 000000/06/3/1971
1910 titl_1 000000/06/3/1971

**Excepted output like** in MY SQL ?




Add
NewCol ID Title LSCNo
1 10 titl_14 000000/06/3/1944
2 19 titl_13 000000/06/3/19
3 561 titl_1 000000/10/125/1955
4 671 titl_1 000000/10/125/1955
5 1765 titl_1 000000/06/65/1976
6 1834 titl_1 000000/06/65/1976
7 1909 titl_1 000000/06/3/1971
8 1910 titl_1 000000/06/3/1971

最佳答案

创建一个变量。类似于:

SELECT @myCount:=@myCount+1 AS NewCol, ID, Title, LSCNo
FROM tutorials_tbl, (SELECT @myCount:= 0) t
WHERE Lscno IN (
SELECT Lscno
FROM tutorials_tbl
GROUP BY Lscno
HAVING COUNT(Lscno) > 1
)
ORDER BY Lscno

关于mysql - 在 MY SQL 中运行 select 语句时如何生成自动增量值列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25599037/

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