Complete the code to calculate a running total of sales ordered by date.
SELECT date, sales, SUM(sales) OVER (ORDER BY [1]) AS running_total FROM sales_data;The running total should be ordered by the date column to accumulate sales over time.
Complete the code to reset the running total for each region.
SELECT region, date, sales, SUM(sales) OVER (PARTITION BY [1] ORDER BY date) AS running_total FROM sales_data;Partitioning by region resets the running total for each region separately.
Fix the error in the code to correctly calculate the running total of sales per customer ordered by date.
SELECT customer_id, date, sales, SUM(sales) OVER (PARTITION BY customer_id ORDER BY [1]) AS running_total FROM sales_data;The running total must be ordered by date to accumulate sales chronologically per customer.
Fill both blanks to calculate a running total of sales per region, ordered by date, and include only sales greater than 100.
SELECT region, date, sales, SUM(sales) OVER (PARTITION BY [1] ORDER BY [2]) AS running_total FROM sales_data WHERE sales > 100;
Partition by region and order by date to get running totals per region over time.
Fill all three blanks to calculate a running total of sales per customer and region, ordered by date, including only sales in 2023.
SELECT customer_id, region, date, sales, SUM(sales) OVER (PARTITION BY [1], [2] ORDER BY [3]) AS running_total FROM sales_data WHERE EXTRACT(year FROM date) = 2023;
Partition by customer_id and region, order by date to get running totals per customer-region over time in 2023.