Skip to content

Latest commit

 

History

History
26 lines (15 loc) · 1.22 KB

File metadata and controls

26 lines (15 loc) · 1.22 KB

SQL Server GROUPING SETS

Setup a sales summary table

Creating an ordinary table is usually not an option in real app since there might be a collision if queries are executed in parallel. The common technique is creating a temporary table per session. This is exactly what we do here:

Run the example above and see that 2 separate queries were executed. The first creates the #sales_summary temporary table and the second uses it.

Temporary table is potentially complex. The same result can be achieved with a subquery. Also, if the same subquery is going to be used several times, it can be refactored to a separate function. Run the following and see same results as above:

GROUPING function

All the features in one example:


< BACK | HOME