How to do it...

Window functions can be used in various ways. Let's get to grips with each one of them in the following sections. For these examples to work, you need to add hire_date_year virtual column

mysql> ALTER TABLE employees ADD hire_date_year YEAR AS (YEAR(hire_date)) VIRTUAL;

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.