O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required