代码之家  ›  专栏  ›  技术社区  ›  Ruchit Rami

SQL数据仓库:“OFFSET”附近的语法不正确

  •  2
  • Ruchit Rami  · 技术社区  · 7 年前

    我正在尝试SQL数据仓库中的一些功能。我试着用SQL数据仓库提供的样本数据集进行偏移。我出错了: Incorrect syntax near 'OFFSET' .

    我已经检查了数据库兼容性版本,它是130(SQL Server 2016)。以下是我正在尝试的查询:

    SELECT [SalesQuotaKey]
          ,[EmployeeKey]
          ,[DateKey]
          ,[CalendarYear]
          ,[CalendarQuarter]
          ,[SalesAmountQuota]
      FROM [dbo].[FactSalesQuota]
      order by [SalesAmountQuota] desc
      OFFSET 0 ROWS  
        FETCH NEXT 10 ROWS ONLY;  
    

    2 回复  |  直到 7 年前
        1
  •  2
  •   Fordyce Garfield TheGameiswar    5 年前

    per docs AzureDW中不支持偏移量提取

    --Azure SQL数据仓库和并行数据仓库的语法

    [订购人

    order\u by\u表达式
    [ASC | DESC]
    }[,…n]

    你可以 simulate OFFSET Fetch 在数据仓库中使用如下行数

    select * from 
    (
    SELECT [SalesQuotaKey]
          ,[EmployeeKey]
          ,[DateKey]
          ,[CalendarYear]
          ,[CalendarQuarter]
          ,[SalesAmountQuota],
    Row_number() over (order by salesamount desc) as rownum
      FROM [dbo].[FactSalesQuota]
    
    )tbl
    where rownum between 1 and 10
    
        2
  •  1
  •   Ron Dunn    7 年前

    如果只需要前n行,请使用TOP子句。

    您希望分页行的用例是什么?ASDW并不是真正为这种查询类型设计的,性能会受到影响。