Named windows

You can name a window and use it as many times as you need rather than redefining it every time:

mysql> SELECT hire_date_year, salary, RANK() OVER w AS 'Rank' FROM employees join salaries ON salaries.emp_no=employees.emp_no WINDOW w AS (PARTITION BY hire_date_year ORDER BY salary DESC) ORDER BY salary DESC LIMIT 10;+----------------+--------+------+| hire_date_year | salary | Rank |+----------------+--------+------+|           1985 | 158220 |    1 ||           1985 | 157821 |    2 ||           1986 | 156286 |    1 ||           1985 | 155709 |    3 ||           1987 | 155513 |    1 ||           1985 | 155377 |    4 ||           1985 | 155190 |    5 ||           1985 | 154888 |    6 ||           1985 | 154885 |    7 ||           1985 | 154459 |    8 |+----------------+--------+------+10 rows in set (8.52 sec)

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.