(PostgreSQL)记录集中的实际记录号 [英] (PostgreSQL) actual record number in recordset
本文介绍了(PostgreSQL)记录集中的实际记录号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
F出于测试目的,我需要编写一个SQL查询,其中包含
实际记录号作为结果集中的一列。如果我的SELECT返回
并返回10条记录,那么我需要有一列
包含值1-10。
Ffor testing purposes I need to write a SQL query which contains the actual record number as a column in the result set. If my SELECT gets back to me with 10 records as the result, I need to have one column which contains the values 1-10.
是否有一种方法可以实现,而无需使用存储过程来浏览
我的数据?
Is there a way to achieve this without a stored procedure cursoring through my data?
我在PostgreSQL上需要它。
I need this on PostgreSQL.
推荐答案
您可以对数据进行分区并获得row_number()
You could partition your data and get a row_number()
例如:
SELECT FirstName, LastName, SalesYTD, PostalCode,
ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS 'Row Number'
FROM Sales.vSalesPerson
WHERE TerritoryName IS NOT NULL AND SalesYTD <> 0;
请参阅以下内容:
ROW_NUMBER(Transact-SQL)
这篇关于(PostgreSQL)记录集中的实际记录号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文