SQL Server 2012:窗口附近的'订单'附近的语法不正确

问题描述:

这应该是一个简单的分区/排序依据...但是我今天有愚蠢的,并且看不到我恶意的方式。SQL Server 2012:窗口附近的'订单'附近的语法不正确

这里的架构和SQL:

create table #NoDiscountFleet 
(fleet_number int, 
customer_key int, 
posyear int, 
posmonth int, 
sale_net_val decimal(16,4), 
sale_tot_qty decimal(12,3), 
FirstDayOfMonth date, 
LastDayOfMonth date 
); 

select fleet_number, 
     lastdayofmonth, 
     tot_fleet_net_sales = sum(sale_net_val) over (partition by fleet_number order by fleet_number,lastdayofmonth) 
from #NoDiscountFleet 
group by fleet_number,lastdayofmonth 
     order by fleet_number; 
+0

我有它的顺序通过在由车队编号分区 - 如此 - 它应该是汇总的驱动因素之一。 – plditallo

你不需要GROUP BY

SELECT fleet_number, 
     lastdayofmonth, 
     tot_fleet_net_sales = SUM(sale_net_val) OVER (PARTITION BY fleet_number 
                 ORDER BY lastdayofmonth) 
FROM #NoDiscountFleet 
ORDER BY fleet_number; 
+0

同样的语法错误 – plditallo

+0

@plditallo然后你确定你使用的数据库与SQL Server 2012 ?,因为该语法工作:http://sqlfiddle.com/#!6/8c118/2 – Lamak

+0

...我知道我今天有*愚蠢的*!我通常在mssql2012服务器上......但今天...我不是 - 我在2008 r2实例上削减了2005年的兼容性,在您验证实例的语法之前,我没有注意到它。非常感谢 - 因为我毫无疑问会浪费更多时间! – plditallo