gpt4 book ai didi

mysql - 从带有索引的选择查询中添加一列

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

我如何从选择查询中添加一列,但新列的值将是选择查询的行数。

select quantity from menu;

然后像这样返回

+--------+
|quantity|
+--------+
| 50 |
| 32 |
| 23 |
+--------+

但是我想要这样的东西

+----------+--------+
|new column|quantity|
+----------+--------+
| 1 | 50 |
| 2 | 32 |
| 3 | 23 |
+----------+--------+

新列应该从 1 开始,从 select 查询语句的行数结束。任何答案都会有所帮助谢谢

最佳答案

you can access the latest version of MySQL ,我们可以简单地使用 Row_Number()功能:

SELECT  
ROW_NUMBER() OVER () AS new_column,
quantity
FROM menu;

关于mysql - 从带有索引的选择查询中添加一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53190392/

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