These queries below both give me exactly the same results, which I assume is because of my dataset rather than how the arguments work.
When using an OVER
clause, what is the difference between ORDER BY
and PARTITION BY
.
On a slightly different note, why not use the term GROUP BY
instead of the more complicated sounding PARTITION BY
, since it seems that using partitioning in this case seems to achieve the same thing as grouping. I know you can alter these inner partitions and that those changes then reflect in the table. Is that the reason?
Query 1:
SELECT
CP.iYear,
AVG(AVG(CP.mUpgradeCost)) OVER(ORDER BY iYear) AS [avg]
FROM ProForma.dbo.CapitalProject CP
GROUP BY CP.iYear
Query 2:
SELECT
CP.iYear,
AVG(AVG(CP.mUpgradeCost)) OVER(PARTITION BY iYear) AS [avg]
FROM ProForma.dbo.CapitalProject CP
GROUP BY CP.iYear