Complete the code to select the total number of orders for each customer.
SELECT customers.name, COUNT(orders.id) AS total_orders FROM customers LEFT JOIN orders ON customers.id = orders.customer_id GROUP BY [1];The GROUP BY clause should group by the customer's unique ID to get the total orders per customer. Grouping by name can cause issues if names are not unique.
Complete the code to find the average order amount per customer.
SELECT customers.name, AVG([1]) AS avg_order_amount FROM customers JOIN orders ON customers.id = orders.customer_id GROUP BY customers.name;The AVG function should be applied to the order amount to find the average per customer.
Fix the error in the code to get the maximum order amount per customer.
SELECT customers.name, MAX([1]) AS max_amount FROM customers JOIN orders ON customers.id = orders.customer_id GROUP BY customers.name;The MAX function should be applied to the order amount to find the highest order per customer.
Fill both blanks to calculate the total quantity ordered per product.
SELECT products.name, SUM([1]) AS total_quantity FROM products JOIN order_items ON products.id = order_items.product_id GROUP BY [2];
SUM should be applied to the quantity column to get total quantity. GROUP BY should be on product name to group results by product.
Fill all three blanks to find the average price per category.
SELECT categories.name AS category_name, AVG([1]) AS avg_price FROM categories JOIN products ON categories.id = products.category_id GROUP BY [2] HAVING AVG([3]) > 50;
AVG should be applied to products.price to calculate average price. GROUP BY should be on category name. HAVING filters categories with average price greater than 50.