gpt4 book ai didi

sql - SQL Azure 中是否支持 PARTITION BY ... ORDER BY

转载 作者:行者123 更新时间:2023-12-03 00:15:08 26 4
gpt4 key购买 nike

我真的很苦恼这个问题,非常感谢任何帮助!我有下面的 SQL 语句,它在 SQL 2012 中完美执行,但在 Azure 中不执行,并显示以下消息:

Msg 40517, Level 15, State 1, Line 2
Keyword or statement option 'ORDER BY' is not supported in this version of SQL Server.

从谷歌搜索我已经完成了 PARTITION BY... 支持 ORDER BY 吗? http://msdn.microsoft.com/en-us/library/ms187810.aspx

SQL Azure and support for CTE syntax?

我已将失败的 SQL 代码粘贴在下面:

SELECT        isnull(ROW_NUMBER() OVER (ORDER BY s.Id), 0) AS Id, DATEPART(YEAR, DATEADD(WEEK, s.SystemWeekId, GETDATE())) AS PredictedYear, DATEPART(MONTH, 
DATEADD(WEEK, s.SystemWeekId, GETDATE())) AS PredictedMonth, s.SystemWeekId AS SystemWeek, s.VehicleId,
(SUM(s.AverageWeeklyKms) OVER (PARTITION BY s.VehicleId ORDER BY s.Id) + NextServiceKilometres) CalculatedKilometres,
CAST(CASE WHEN (((FLOOR((SUM(s.AverageWeeklyKms) OVER (PARTITION BY s.VehicleId ORDER BY s.Id) + NextServiceKilometres) / 1000)) * 1000)) % PreventativeKilometreInterval = 0 THEN
(SELECT ServiceTypeId
FROM ServiceTypes
WHERE ServiceTypeDescription =
(SELECT ParameterValue
FROM SystemParameters
WHERE ParameterName = 'PreventativeService')) WHEN (((FLOOR((SUM(s.AverageWeeklyKms) OVER (PARTITION BY s.VehicleId
ORDER BY s.Id) + NextServiceKilometres) / 1000)) * 1000)) % MajorKilometreInterval = 0 THEN
(SELECT ServiceTypeId
FROM ServiceTypes
WHERE ServiceTypeDescription =
(SELECT ParameterValue
FROM SystemParameters
WHERE ParameterName = 'MajorService')) WHEN (((FLOOR((SUM(s.AverageWeeklyKms) OVER (PARTITION BY s.VehicleId
ORDER BY s.Id) + NextServiceKilometres) / 1000)) * 1000)) % MinorKilometreInterval = 0 THEN
(SELECT ServiceTypeId
FROM ServiceTypes
WHERE ServiceTypeDescription =
(SELECT ParameterValue
FROM SystemParameters
WHERE ParameterName = 'MinorService')) ELSE 0 END AS INT) AS ServiceTypeId
FROM Temp AS s

最佳答案

Azure Sql 数据库服务器版本 V12 支持 PARTITION BY...ORDER BY: https://msdn.microsoft.com/en-us/library/ms187810.aspx

关于sql - SQL Azure 中是否支持 PARTITION BY ... ORDER BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25085021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com