Session Ready
Exercise

Calculating distinct counts

The COUNT() function has a variant which can be quite useful: COUNT(DISTINCT). This distinct count function allows us to calculate the number of unique elements in a data set, so COUNT(DISTINCT x.Y) will get the unique number of values for column Y on the table aliased as x.

In this example, we will continue to look at incident rollup data in the dbo.IncidentRollup table. Management would like to know how many unique incident types we have in our three-month data set as well as the number of days with incidents. They already know the total number of incidents because you gave them that information in the last exercise.

Instructions
100 XP
  • Return the count of distinct incident type IDs as NumberOfIncidentTypes

  • Return the count of distinct incident dates as NumberOfDaysWithIncidents

  • Fill in the appropriate function call and input column to determine number of unique incident types and number of days with incidents in our rollup table.