How to use separation in order and in order?

I am using SQL Server 2008 R2.

I am trying to write a query showing the following:

select productname, unitprice,categoryid, sum(unitprice) 
over (partition by categoryid order by unitprice desc) As PriceSum
from Products

I want the result to order products at their unit price, when dividing the products into their categories. I get this error: Incorrect syntax near 'order'. What am I doing wrong?

+5
source share
1 answer

You are not doing anything wrong. SQL Server 2008 does not support running aggregates with window functionality.

SQL Server 2012 finally has full support for window features, including aggregate startup. Therefore, if you really need it, you will need to upgrade.

See this SQLFiddle for SQL Server 2012: http://sqlfiddle.com/#!6/5303f/1

+9
source

All Articles