Given two SQL snippets using GROUP BY and SUM() OVER(), what are their outputs?
Asked in the First round stage. Use the sales table and evaluate these PostgreSQL queries:
SELECT department, SUM(amount) AS total_amount
FROM sales
GROUP BY department
ORDER BY department NULLS LAST;
SELECT department,
SUM(SUM(amount)) OVER () AS grand_total
FROM sales
GROUP BY department
ORDER BY department NULLS LAST;
query_name, department, and result_value.grouped_total and rows from the second query window_grand_total.| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sale identifier |
| department | VARCHAR(50) | Department associated with the sale |
| amount | NUMERIC(10,2) | Sale amount, which may be NULL |