Book Image

MySQL 8 Cookbook

By : Karthik Appigatla
Book Image

MySQL 8 Cookbook

By: Karthik Appigatla

Overview of this book

MySQL is one of the most popular and widely used relational databases in the World today. The recently released MySQL 8 version promises to be better and more efficient than ever before. This book contains everything you need to know to be the go-to person in your organization when it comes to MySQL. Starting with a quick installation and configuration of your MySQL instance, the book quickly jumps into the querying aspects of MySQL. It shows you the newest improvements in MySQL 8 and gives you hands-on experience in managing high-transaction and real-time datasets. If you've already worked with MySQL before and are looking to migrate your application to MySQL 8, this book will also show you how to do that. The book also contains recipes on efficient MySQL administration, with tips on effective user management, data recovery, security, database monitoring, performance tuning, troubleshooting, and more. With quick solutions to common and not-so-common problems you might encounter while working with MySQL 8, the book contains practical tips and tricks to give you the edge over others in designing, developing, and administering your database effectively.
Table of Contents (20 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

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 row within its partition
  • PERCENT_RANK(): Percentage rank value
  • RANK(): Rank of the current row within its partition, with gaps
  • ROW_NUMBER(): Number of the current row within its partition

How to do it...

Window functions can be used in various ways. Let's get to...