content_image/819100.jpg
<img src='content_image/819100.jpg'>

Each window operation in the query is signified by inclusion of an OVER  clause that specifies how to partition query rows into groups for processing by the window function: 

•The first OVER  clause is empty, which treats the entire set of query rows as a single partition. The window function thus produces a global sum, but does so for each row. 

•The second OVER  clause partitions rows by country, producing a sum per partition (per country). The function produces this sum for each partition row. 

Window functions are permitted only in the select list and ORDER BY  clause. Query result rows are determined from the FROM  clause, after WHERE , GROUP BY , and HAVING  processing, and windowing execution occurs before ORDER BY , LIMIT , and SELECT DISTINCT . 

The OVER  clause is permitted for many aggregate functions, which therefore can be used as window or nonwindow functions, depending on whether the OVER  clause is present or absent: 

AVG() BIT_AND() BIT_OR() BIT_XOR() COUNT() JSON_ARRAYAGG() JSON_OBJECTAGG() MAX() MIN() STDDEV_POP(), STDDEV(), STD() STDDEV_SAMP() SUM() VAR_POP(), VARIANCE() VAR_SAMP() 

For details about each aggregate function, see Section 12.20.1, “Aggregate Function Descriptions” . 

MySQL also supports nonaggregate functions that are used only as window functions. For these, the OVER clause is mandatory: 

CUME_DIST() DENSE_RANK() FIRST_VALUE() LAG() LAST_VALUE() LEAD() NTH_VALUE() NTILE() PERCENT_RANK() RANK() ROW_NUMBER() 

For details about each nonaggregate function, see Section 12.21.1, “Window Function Descriptions” . 

