Consider a table sales with columns region, salesperson, and amount. Which statement best describes the difference in output rows when using GROUP BY region versus using SUM(amount) OVER (PARTITION BY region)?
Think about how GROUP BY collapses rows versus how window functions keep all rows.
GROUP BY groups rows and returns one row per group, aggregating values. Window functions compute aggregates but keep all original rows, repeating the aggregate value for each row in the partition.
Given the table orders with 10 rows, what is the number of rows returned by these queries?
1) SELECT region, SUM(amount) FROM orders GROUP BY region; 2) SELECT region, amount, SUM(amount) OVER (PARTITION BY region) FROM orders;
GROUP BY reduces rows to groups; window functions keep all rows.
GROUP BY returns one row per group (region). Window function returns all original rows with an added column showing the sum per region.
Which SQL query correctly uses a window function to calculate the running total of amount ordered by order_date?
SELECT order_id, amount, SUM(amount) OVER (ORDER BY order_date) AS running_total FROM orders;
Window functions require OVER() with correct clauses like ORDER BY or PARTITION BY.
Option B correctly uses SUM() as a window function with ORDER BY inside OVER(). Others have syntax errors or misuse clauses.
Which statement about performance is generally true when comparing GROUP BY and window functions on large datasets?
Think about how grouping reduces rows versus window functions keeping all rows.
GROUP BY reduces rows early, which can speed up queries. Window functions keep all rows and compute aggregates over partitions, which can be more costly.
What error will this query produce?
SELECT region, salesperson, SUM(amount) OVER () FROM sales GROUP BY region;
Check which columns are selected and how GROUP BY works with non-aggregated columns.
The query selects salesperson but does not group by it or aggregate it, causing an error. Window functions can be used with GROUP BY but columns must be valid.