Grouping Sets are an effective way to add subtotals to aggregated queries. T His article explains how.
This series is designed to give you some challenges in writing T-SQL queries that can improve your skills. The following are the articles in the series.
- Creating Compound Interest Calculations in SQL
- Generating Completely Random Sample Output from a Dataset
- Segment Data into Deciles
- Display Median Values
- Using a Derived Table to Compare Data with Values from a Previous Year
- Using a CTE as a Tally Table
- Aggregate Data for the Last Day of the Month
- Count the Number of Weekend Days between Two Dates
These article is adapted from the book “Query Answers with SQL Server Volume II: In-Depth Querying” by Adam and Karine Aspin. Available as both a paperback and an eBook from all good resellers including Amazon, Kobo and iBooks, as well as all good bookstores.
The sample data is available either in the accompanying material for this article, or on the Tetras Publishing website at: www.tetraspublishing.com/sqlserver.