Hi ,
How can i implement those 2 function in a simple SQL query ? i have a database that done support this 2 functions ,
input -
class rollno section marks stuName
A 1 a 80 manoj
A 2 a 70 harish
A 3 a 80 kanchan
A 4 b 90 pooja
A 5 b 90 saurabh
A 6 b 50 anita
B 1 a 60 nitin
B 2 a 50 kamar
B 3 a 80 dinesh
B 4 b 90 paras
B 5 b 50 lalit
B 6 b 70 hema
rollup example
select class, section, sum(marks) [sum]
from #tempTable
group by class, section with ROLLUP
Output:
class section sum
A a 230
A b 230
A NULL 460 -- 230 + 230 = 460
B a 190
B b 210
B NULL 400 -- 190 + 210 = 400
NULL NULL 860 -- 460 + 400 = 860
cube exmaple -
select class, section, sum(marks) [sum]
from #tempTable
group by class, section with CUBE
Output:
class section sum
A a 230
A b 230
A NULL 460 -- 230 + 230 = 460
B a 190
B b 210
B NULL 400 -- 190 + 210 = 400
NULL NULL 860 -- 460 + 400 = 860
NULL a 420 -- 230 + 190 = 420
NULL b 440 -- 230 + 210 = 440