Complete the code to define a named window called w1 that orders rows by the column 'date'.
SELECT *, ROW_NUMBER() OVER w1 FROM sales [1];The WINDOW clause defines a named window 'w1' with ordering by 'date'. This allows reuse of the window specification.
Complete the code to use the named window 'w1' in the ROW_NUMBER() function.
SELECT *, ROW_NUMBER() OVER [1] FROM sales WINDOW w1 AS (ORDER BY date);To use a named window, just put its name inside the OVER() clause without extra keywords.
Fix the error in the WINDOW clause that tries to define a window named w2 partitioned by 'region' and ordered by 'sales'.
SELECT *, SUM(sales) OVER w2 FROM sales WINDOW w2 AS [1];The correct syntax for partitioning is PARTITION BY column_name. The original code missed the BY keyword.
Fill both blanks to define two named windows: w1 partitions by 'category', w2 orders by 'date'.
SELECT *, SUM(amount) OVER w1, ROW_NUMBER() OVER w2 FROM transactions WINDOW w1 AS ([1]), w2 AS ([2]);
w1 partitions rows by 'category', so it uses PARTITION BY category. w2 orders rows by 'date', so it uses ORDER BY date.
Fill all three blanks to define a named window w3 that partitions by 'department', orders by 'salary', and uses ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
SELECT *, SUM(salary) OVER w3 FROM employees WINDOW w3 AS ([1] [2] [3]);
The window w3 partitions by 'department', orders by 'salary', and defines the frame as ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW for cumulative sum.