IKH

Named Windows

In the previous segment, you learnt that we can use multiple window functions in the same query. Now, you may have noticed that in one of the queries, we used the same window in both the window functions. This makes the code heavier and difficult to tweak as and when the need arises. So, in this segment, you will learn how to create, store and use named windows.

Let’s watch the upcoming video as Shreyas explains this in detail.

So, as you learnt in this video, the same window can be used to define multiple ‘over’ clauses.  You can define the window once, give it a name and then refer to the name in the ‘over’ clauses. A named window makes it easier to experiment with multiple window definitions and observe their effects on the query results. You only need to modify the window definition in the ‘window’ clause, rather than using multiple ‘over’ clause definitions.

The syntax for writing a named window is as follows:

The order in which the various SQL statements appear in a query is as follows:

  • SELECT
  • FROM
  • JOIN
  • WHERE
  • GROUP BY
  • HAVING
  • WINDOW
  • ORDER BY

In the next segment, you will learn another construct in SQL known as a frame. It is used to group data from multiple consecutive rows together and perform operations on them. 

The MySQL documentation is a good resource in case you need more clarity on any concept(s). You can refer to the link provided below to learn more about named windows.

Report an error