On January 28th at 9:00 UTC Academy will be unavailable for 10 minutes due to planned maintenance break.
Kickstart 2020 with new opportunities! - hours only!Up to 80% off on all courses and bundles.-Close
Dealing with dates
Working with time data
Date and time date
Extracting dates and times
25. Using the DATEPART() function in grouping
Doing arithmetic with dates
Converting date and time data
Building date and time data from parts
Summary and review


Nice! You can also use the DATEPART() function to group data. Let's analyze the example below:

  AVG(Delay) AS AvgDelay,
  DATEPART(year, Date) AS Year,
  DATEPART(quarter, Date) AS Quarter
FROM Flight
  DATEPART(quarter, Date);

This query calculates the average delay for all flights and groups the calculation results by quarter.

Let's practice using DATEPART() with grouping.


Help the manager prepare a report about the routes that PerfectAir flies. Show the average delay for each hour of arrival time. Name the columns Hour and AvgDelay.