Complete the code to find the total sales for each product.
SELECT product_id, SUM([1]) FROM sales GROUP BY product_id;The SUM function adds up the values in the specified column. Here, we want to sum the quantity sold for each product.
Complete the code to count how many orders each customer made.
SELECT customer_id, COUNT([1]) FROM orders GROUP BY customer_id;The COUNT function counts the number of non-null values in the specified column. Counting order_id gives the number of orders per customer.
Fix the error in the query to find the average price per category.
SELECT category, AVG([1]) FROM products GROUP BY category;The AVG function calculates the average of numeric values. We must use the price column to get the average price per category.
Fill both blanks to find the maximum and minimum order amounts per customer.
SELECT customer_id, [1](order_amount), [2](order_amount) FROM orders GROUP BY customer_id;
MAX finds the highest value, and MIN finds the lowest value in a group. Here, they show the biggest and smallest order amounts per customer.
Fill all three blanks to find the average, total, and count of sales per region.
SELECT region, [1](sales_amount), [2](sales_amount), [3](sales_amount) FROM sales_data GROUP BY region;
AVG calculates the average sales, SUM adds all sales, and COUNT counts the number of sales entries per region.