SQL Data warehouse: Incorrect syntax near 'OFFSET'

给你一囗甜甜゛ 提交于 2019-12-11 00:33:21

问题


I am trying out few functionalities in SQL data warehouse. I was trying out OFFSET with sample dataset provided with SQL data warehouse. I got error: Incorrect syntax near 'OFFSET'.

I have checked the database compatibility version and it is 130(SQL Server 2016). Following is the query I am trying:

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

Is there anything I am missing in query or do I need to do any settings change to enable using OFFSET?


回答1:


As per docs Offset Fetch is not supported in AzureDW

-- Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse

[ ORDER BY
{
order_by_expression
[ ASC | DESC ]
} [ ,...n ]
]

You can simulate OFFSET Fetch in DW using RowNumber like below

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:


If you only ever want the first 'n' rows, use the TOP clause.

What is the use case where you'd want to page the rows? ASDW isn't really designed for this query type, performance will suffer.



来源:https://stackoverflow.com/questions/47346905/sql-data-warehouse-incorrect-syntax-near-offset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!