MS Access 相当于 ROW_NUMBER() 和 OVER()

问题描述 投票:0回答:1

我在 sql server 中运行了以下 sql 语句 -

SELECT Id,Name
       FROM
       (
          SELECT ROW_NUMBER() OVER( ORDER BY Id DESC ) AS row, Id, Name from BRS 
       )
AS data WHERE row BETWEEN 1 AND 5 ORDER BY Id DESC;

现在,我想在 MS Access 数据库中实现相同的技术。但它给出了

ROW_NUMBER() and OVER()

的语法错误

是否有

ROW_NUMBER() and OVER()
的 MS Access 2007 语法?

sql ms-access lazy-loading
1个回答
0
投票

你可以这样做:

SELECT TOP 5 
    (Select Count(*) From BRS As B Where B.Id >= BRS.Id) As Row,
    BRS.Id, 
    BRS.Name
FROM 
    BRS
ORDER BY 
    BRS.Id DESC;

结果:

Id  Name    Row
10  Test    1
9   TestTwo 2
8   Thing   3
6   Another 4
5   Anyone  5
© www.soinside.com 2019 - 2024. All rights reserved.