我正在使用 SQL Server 2008 R2。
我正在尝试编写一个显示以下内容的查询:
select productname, unitprice,categoryid, sum(unitprice)
over (partition by categoryid order by unitprice desc) As PriceSum
from Products
我希望结果按单价对产品进行排序,同时按类别对产品进行分区。我收到此错误:Incorrect syntax near 'order'.
我究竟做错了什么?
你没有做错什么。 SQL Server 2008 不支持使用窗口函数运行聚合。
SQL Server 2012 终于完全支持窗口函数,包括运行聚合。因此,如果您确实需要此功能,则需要升级。
请参阅 SQL Server 2012 的 SQLFiddle:http://sqlfiddle.com/#!6/5303f/1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)