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

Window functions

By using window functions, for each row from a query, you can perform a calculation using rows related to that row. This is accomplished by using the OVER and WINDOW clauses.

Here is the list of calculations that you can do:

  • CUME_DIST(): Cumulative distribution value
  • DENSE_RANK(): Rank of the current row within its partition, without gaps
  • FIRST_VALUE(): The value of the argument from the first row of the window frame
  • LAG(): The argument value from the row lagging the current row within partition
  • LAST_VALUE(): Value of argument from the first row of window frame
  • LEAD(): Value of argument from row leading current row within partition
  • NTH_VALUE(): Argument value from n-th row of window frame
  • NTILE(): Bucket number of the current ...

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