Rainbow Deals - 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
23. Using YEAR(), MONTH(), and DAY() with aggregate functions
Doing arithmetic with dates
Converting date and time data
Building date and time data from parts
Summary and review


You can use these functions with GROUP BY or HAVING. This is especially useful when preparing reports. The query below can be used to generate a report about the number of aircraft produced each month:

  YEAR(ProducedDate) AS Year,
  MONTH(ProducedDate) AS Month,
  COUNT(Id) AS FlightsNumber
FROM Aircraft
GROUP BY YEAR(ProducedDate),

As you can see, rows are grouped by the extracted YEAR and MONTH values.


The manager needs a report of the average delay, in minutes, of all flights for each year after 2014. Write the query for this report. Name the columns Year and AvgDelay.