Singularity has it - just wrong column in the partition by:declare @t table (Section char(1), Name varchar(10), rollNo int, marks int)insert @tselect 'A', 'TOM', 1, 90 union allselect 'A', 'HARRY', 2, 80 union allselect 'A', 'JOHN', 3, 80 union allselect 'A', 'TOM', 4, 90 union allselect 'B', 'CHRIS', 5, 90 union allselect 'B', 'CHRIS', 6, 80select Section ,Name ,RollNo ,sum(marks) over (partition by section) as [sum(marks)1] ,sum(marks) over (partition by section, name) [sum(marks)2]from @torder by rollNooutput:Section Name RollNo sum(marks)1 sum(marks)2------- ---------- ----------- ----------- -----------A TOM 1 340 180A HARRY 2 340 80A JOHN 3 340 80A TOM 4 340 180B CHRIS 5 170 170B CHRIS 6 170 170
Be One with the OptimizerTG