![]() The empty set ‘( )’ in GROUPING SETS() generates grand total. GROUP BY GROUPING SETS ((, ), ( ), ())Īs the sets we have specified generate sub-total and a grand-total row, the same result set can be produced by using GROUP BY ROLLUP(). The above result set can be achieved by a single GROUPING SETS() clause as below: SELECT NULL, NULL, SUM (SalesYTD ) AS 'Total Sales' ![]() SELECT, NULL, SUM (SalesYTD ) AS 'Total Sales' SELECT, , SUM (SalesYTD ) AS 'Total Sales' To summarize this data we can use GROUP BY, to summarize by more that one set we need multiple SELECTs, and UNION ALL to merge the result set: GROUPING SETS() generates the result by producing a UNION ALL set of the result sets generated by specified grouping sets. ![]() By using GROUPING SETS() we can specify multiple groupings in a single query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |