From the course: Advanced SQL – Window Functions

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Aggregate window functions

Solution: Aggregate window functions - SQL Tutorial

From the course: Advanced SQL – Window Functions

Start my 1-month free trial

Solution: Aggregate window functions

- [Instructor] First, I'll find the number of annual vaccinations. This is a simple query grouped by year using a count star to aggregate the number of vaccinations. I don't need anything else from the table. Only the years that had vaccinations and their vaccination count. I always like to have the results of the previous step in front of me as I'm working on the next one. That's why after every CTE, I add a select star from it and comment it out as I go. I often find that I need to go back to previous ones for debugging. I'm now ready to calculate the average for the previous two years. I'm going to break the solution to multiple steps, probably more than necessary, but just to make it easier to follow and to avoid needing to repeat long expressions. I also use highly descriptive long aliases even if it makes the query longer. Remember, you can always go back and compact it. I'll use the previous CTE as my input…

Contents