You can use GROUP BY additionally with GROUPING SETS.
If you've been useing GROUP BY for a number of columns, now imagine those columns as sets, and everything is the same. When you use sets to make the groupation you have to add the GROUPING SETS as reserved words.
For example, the following select using GROUPING SETS
SELECT Region, Department, avg(sal) AverageSalary
from tblEmployee
Group BY
GROUPING SETS
(
(Region, Department)
/*
(Region),
(Department) ,
()
*/
)
is equal to the following with only GROUP BY
SELECT Region, Department, avg(sal) AverageSalary
from tblEmployee
Group BY
Region, Department
Regards,
IgorMi
Igor Micev,My blog: www.igormicev.com