1.you can now add aggregate functions to any SELECT (even without a GROUP BY clause) by specifying an OVER() partition for each function.
2.SUM(..) OVER(..) is most useful for calculating a Total or percentage of a total for each row
3.SUM() function works with any of the other aggregate functions as well, such as MIN() or AVG()
- Partition by
-
Divides the result set into partitions. The window function is applied to each partition separately and computation restarts for each partition.
select
StudentId,
StudentName,
Subject,
Mark,
sum(Mark) OVER (Partition by StudentId) as Total
from
Student
Output
=====
StudentId StudentName Subject Mark Total
======= ========== ===== ==== =====
1 Raja Physics 80 240
1 Raja Maths 90 240
1 Raja Biology 70 240
2 Sam Physics 90 150
2 Sam Maths 60 150
Popularity: 3% [?]

December 2nd, 2008
admin
Posted in
Tags: 
