Complete the code to group the sales by the product_id.
SELECT product_id, SUM(quantity) FROM sales GROUP BY [1];We group by product_id to aggregate sales per product.
Complete the code to group sales by both product_id and store_id.
SELECT product_id, store_id, SUM(quantity) FROM sales GROUP BY [1], store_id;We group by both product_id and store_id to get totals per product per store.
Fix the error in the GROUP BY clause to correctly group by customer_id.
SELECT customer_id, COUNT(*) FROM orders GROUP BY [1];The GROUP BY clause must use the column name customer_id, not an aggregate or table name.
Fill both blanks to group sales by year and month.
SELECT EXTRACT([1] FROM sale_date) AS year, EXTRACT([2] FROM sale_date) AS month, SUM(amount) FROM sales GROUP BY year, month;
We extract year and month from sale_date to group sales by these periods.
Fill all three blanks to group employees by department and job title, showing average salary.
SELECT [1], [2], AVG(salary) FROM employees GROUP BY [3], job_title;
We select and group by department and job_title to get average salary per group.
