1. Learn
  2. /
  3. Courses
  4. /
  5. Time Series Analysis in SQL Server

Exercise

Combine multiple aggregations in one query

In the last three exercises, we walked through the ROLLUP, CUBE, and GROUPING SETS grouping operators. Of these three, GROUPING SETS is the most customizable, allowing you to build out exactly the levels of aggregation you want. GROUPING SETS makes no assumptions about hierarchy (unlike ROLLUP) and can remain manageable with a good number of columns (unlike CUBE).

In this exercise, we want to test several conjectures with our data:

  1. We have seen fewer incidents per month since introducing training in November of 2019.
  2. More incidents occur on Tuesday than on other weekdays.
  3. More incidents occur on weekends than weekdays.

Instructions

100 XP

Fill out the grouping sets based on our conjectures above. We want to see the following grouping sets in addition to our grand total:

  • One set by calendar year and month
  • One set by the day of the week
  • One set by whether the date is a weekend or not