sej2008 (12/8/2013)
Why should one use grouping sets when group by is available .how does it help?
GROUPING SETS is less frequently used, but sometimes it can be useful if you're aware of its usefulness.
For example, the result set of this query will be first grouped by the grouping set (Region, Department), and then by City.
SELECT Region, Department, avg(sal) AverageSalary
from tblEmployee
Group BY
GROUPING SETS
(
(Region, Department),
(City)
)
In this case the above select will not return the same ordered result set as
SELECT Region, Department, avg(sal) AverageSalary
from tblEmployee
Group BY
Region, Department, City
Having got the example from the previous post, now you should have understood grouping sets...
Regards,
IgorMi
Igor Micev,My blog: www.igormicev.com