gpt4 book ai didi

sql - 如何查找记录的行号?

转载 作者:行者123 更新时间:2023-12-04 10:21:13 25 4
gpt4 key购买 nike

考虑下面的示例表

ProductDetailNo    ProductDescription
224 Apples
225 Tomatoes
226 Potatoes

如何列出所选行的行号,如下所示?
RowNo    ProductDetailNo          Product Description
2 225 Tomatoes

在我的查询中使用 row_number() 只会为单个记录始终返回 1,无论数据库中的逻辑行是什么。

谢谢,达米安。

最佳答案

试试这个

WITH MyTable AS
(
SELECT ProductDetailNo, ProductDescription,
ROW_NUMBER() OVER ( ORDER BY ProductDetailNo ) AS 'RowNumber'
FROM Product
)
SELECT RowNumber, ProductDetailNo
FROM MyTable
WHERE ProductDetailNo = 225

关于sql - 如何查找记录的行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8738785/

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