如何在SQL2005上对此查询应用偏移量?
SELECT [name],[phone]
FROM (
SELECT *,Row_Number() Over (Partition By phone Order By (Select Null)) AS RN
FROM Table1
) AS T
Where RN = 1
由于
答案 0 :(得分:1)
OFFSET,但您可以使用以下approuch来执行此操作。 如果您要选择从按名称排序的90到100之间的10条记录,则可以使用以下查询
;with data as
(
SELECT [name],[phone]
FROM (
SELECT *,Row_Number() Over (Partition By phone Order By (Select Null)) AS RN
FROM Table1
) AS T
Where RN = 1
)
select * from
( select top(10) * from
( select top(100) * from data order by name asc )
t1 order by name desc
) t2 order by name
答案 1 :(得分:0)
我自己解决了这个问题。我使用此查询(具有不同的列名称)
with CTE as (
SELECT cFullname,BuyerPhoneNumber
FROM (
SELECT *,Row_Number() Over (Partition By BuyerPhoneNumber Order By (Select Null)) AS RN
FROM [Order]
) AS T
Where RN = 1
)
SELECT *
FROM (
SELECT Row_Number() OVER (ORDER BY cFullname ASC) AS CI_offset_row_number, *
FROM CTE
) AS A
WHERE A.CI_offset_row_number BETWEEN (21) AND (30)