SQL Server选择排名前10-20的结果?

我有两列,第一列是我想要排名前10位的产品(1-10)

那是

SELECT TOP 10 * FROM Product

在第二列中,我想要接下来的10个结果(11-20)

我怎么做?

回答:

WITH T AS

(

SELECT TOP 20 name,

row_number() OVER (ORDER BY id) AS RN

FROM Products

ORDER BY id

)

SELECT

MAX(CASE WHEN RN <=10 THEN name END) AS Col1,

MAX(CASE WHEN RN > 10 THEN name END) AS Col2

FROM T

GROUP BY RN % 10

以上是 SQL Server选择排名前10-20的结果? 的全部内容, 来源链接: utcz.com/qa/411312.html

回到顶部