End of Summer - hours only!Up to 80% off on all courses and bundles.-Close
Customer cohorts


Very well done! Let's do one more exercise.


Find the registration count for each week in each year. Show the following columns: registration_year, registration_week, and registration_count. Order the results by the year and week.

Note: When a week overlaps two years, different databases will behave differently. You need to check your database's documentation to see how your database will classify days in this week. For example: let's consider two days: December 30th, 2019 and January 5th, 2020 (Monday and Sunday of the same week).

  • In PostgreSQL (which we use in this course): the database treats that week as one week: every day will be classified as week 1 of 2020.
  • In SQL Server: the database splits that week's days into two different weeks. December 30th and 31st will be classified as week 53 of 2019, while January 1st—5th will be classified as week 1 of 2020.

Stuck? Here's a hint!

To get the week number from a date, use:

DATE_PART('week', registration_date)