[ { "id": "q1", "title": "List electronics products", "difficulty": "Beginner", "description": "Retrieve the names and sale amounts of all products in the Electronics category.", "hint": "Use WHERE clause to filter by category.", "expected_sql": "SELECT product_name, sale_amount FROM sales WHERE category = 'Electronics';" }, { "id": "q2", "title": "Find sales after specific date", "difficulty": "Beginner", "description": "Show all sales that occurred after January 5, 2023.", "hint": "Use WHERE clause with date comparison.", "expected_sql": "SELECT product_name, sale_date FROM sales WHERE sale_date > '2023-01-05';" }, { "id": "q3", "title": "List orders by customer", "difficulty": "Beginner", "description": "Retrieve all orders placed by customer with ID 2001.", "hint": "Use WHERE clause to filter by customer_id.", "expected_sql": "SELECT order_id, product_id, order_date FROM orders WHERE customer_id = 2001;" }, { "id": "q4", "title": "Find high-value sales", "difficulty": "Beginner", "description": "Show products with a sale amount greater than 1000.", "hint": "Use WHERE clause to filter by sale_amount.", "expected_sql": "SELECT product_name, sale_amount FROM sales WHERE sale_amount > 1000;" }, { "id": "q5", "title": "List unique categories", "difficulty": "Beginner", "description": "Retrieve all unique product categories from the sales table.", "hint": "Use DISTINCT to avoid duplicate categories.", "expected_sql": "SELECT DISTINCT category FROM sales;" }, { "id": "q6", "title": "Find orders with quantity greater than 1", "difficulty": "Beginner", "description": "Show order details where the quantity is greater than 1.", "hint": "Use WHERE clause to filter by quantity.", "expected_sql": "SELECT order_id, product_id, quantity FROM orders WHERE quantity > 1;" }, { "id": "q7", "title": "List sales by date", "difficulty": "Beginner", "description": "Show all sales ordered by sale date.", "hint": "Use ORDER BY clause on sale_date.", "expected_sql": "SELECT product_name, sale_date FROM sales ORDER BY sale_date;" }, { "id": "q8", "title": "Find accessories sales", "difficulty": "Beginner", "description": "Retrieve all sales from the Accessories category.", "hint": "Use WHERE clause to filter by category.", "expected_sql": "SELECT product_name, sale_amount FROM sales WHERE category = 'Accessories';" }, { "id": "q9", "title": "List order quantities", "difficulty": "Beginner", "description": "Show the quantity for each order.", "hint": "Select quantity from orders table.", "expected_sql": "SELECT order_id, quantity FROM orders;" }, { "id": "q10", "title": "Find sales with low amounts", "difficulty": "Beginner", "description": "Retrieve products with a sale amount less than 100.", "hint": "Use WHERE clause to filter by sale_amount.", "expected_sql": "SELECT product_name, sale_amount FROM sales WHERE sale_amount < 100;" }, { "id": "q11", "title": "Total revenue by category", "difficulty": "Intermediate", "description": "Calculate the total sale amount for each product category.", "hint": "Use GROUP BY on category and SUM on sale_amount.", "expected_sql": "SELECT category, SUM(sale_amount) AS total_revenue FROM sales GROUP BY category;" }, { "id": "q12", "title": "Count orders per product", "difficulty": "Intermediate", "description": "Show the number of orders for each product.", "hint": "Join sales and orders, then GROUP BY product_name.", "expected_sql": "SELECT s.product_name, COUNT(o.order_id) AS order_count FROM sales s JOIN orders o ON s.id = o.product_id GROUP BY s.product_name;" }, { "id": "q13", "title": "Average sale amount per product", "difficulty": "Intermediate", "description": "Find the average sale amount for each product name.", "hint": "Use GROUP BY on product_name and AVG on sale_amount.", "expected_sql": "SELECT product_name, AVG(sale_amount) AS avg_sale FROM sales GROUP BY product_name;" }, { "id": "q14", "title": "Customer order count", "difficulty": "Intermediate", "description": "Show the number of orders placed by each customer.", "hint": "Use GROUP BY on customer_id and COUNT.", "expected_sql": "SELECT customer_id, COUNT(order_id) AS order_count FROM orders GROUP BY customer_id;" }, { "id": "q15", "title": "High quantity orders", "difficulty": "Intermediate", "description": "List orders with a total quantity greater than 2.", "hint": "Use GROUP BY on order_id and HAVING clause.", "expected_sql": "SELECT order_id, SUM(quantity) AS total_quantity FROM orders GROUP BY order_id HAVING total_quantity > 2;" }, { "id": "q16", "title": "Products not ordered", "difficulty": "Intermediate", "description": "List products that have not been ordered.", "hint": "Use LEFT JOIN and check for NULL in orders table.", "expected_sql": "SELECT s.product_name FROM sales s LEFT JOIN orders o ON s.id = o.product_id WHERE o.order_id IS NULL;" }, { "id": "q17", "title": "Order details with products", "difficulty": "Intermediate", "description": "Show order details including product names and quantities.", "hint": "Join sales and orders tables.", "expected_sql": "SELECT o.order_id, s.product_name, o.quantity FROM orders o JOIN sales s ON o.product_id = s.id;" }, { "id": "q18", "title": "Total quantity per customer", "difficulty": "Intermediate", "description": "Calculate the total quantity of items ordered by each customer.", "hint": "Use GROUP BY on customer_id and SUM on quantity.", "expected_sql": "SELECT customer_id, SUM(quantity) AS total_quantity FROM orders GROUP BY customer_id;" }, { "id": "q19", "title": "Orders by date range", "difficulty": "Intermediate", "description": "List all orders placed between January 1, 2023, and January 5, 2023.", "hint": "Use BETWEEN clause for date range.", "expected_sql": "SELECT order_id, customer_id, order_date FROM orders WHERE order_date BETWEEN '2023-01-01' AND '2023-01-05';" }, { "id": "q20", "title": "Most ordered product category", "difficulty": "Intermediate", "description": "Find the category with the highest number of orders.", "hint": "Join sales and orders, group by category, and use LIMIT.", "expected_sql": "SELECT s.category, COUNT(o.order_id) AS order_count FROM sales s JOIN orders o ON s.id = o.product_id GROUP BY s.category ORDER BY order_count DESC LIMIT 1;" }, { "id": "q21", "title": "Total revenue per customer", "difficulty": "Advanced", "description": "Calculate the total revenue (sale_amount * quantity) generated by each customer.", "hint": "Join sales and orders, multiply sale_amount by quantity, and group by customer_id.", "expected_sql": "SELECT o.customer_id, SUM(s.sale_amount * o.quantity) AS total_revenue FROM orders o JOIN sales s ON o.product_id = s.id GROUP BY o.customer_id;" }, { "id": "q22", "title": "Most expensive ordered product", "difficulty": "Advanced", "description": "Find the product with the highest sale amount that was ordered.", "hint": "Join sales and orders, use ORDER BY and LIMIT.", "expected_sql": "SELECT s.product_name, s.sale_amount FROM sales s JOIN orders o ON s.id = o.product_id ORDER BY s.sale_amount DESC LIMIT 1;" }, { "id": "q23", "title": "Daily revenue trend", "difficulty": "Advanced", "description": "Show the total revenue (sale_amount * quantity) per day for all orders.", "hint": "Join tables, group by order_date, and calculate revenue.", "expected_sql": "SELECT o.order_date, SUM(s.sale_amount * o.quantity) AS daily_revenue FROM orders o JOIN sales s ON o.product_id = s.id GROUP BY o.order_date;" }, { "id": "q24", "title": "Customers with high-value orders", "difficulty": "Advanced", "description": "Identify customers whose total order value exceeds 2000.", "hint": "Join tables, calculate total value, and use HAVING clause.", "expected_sql": "SELECT o.customer_id, SUM(s.sale_amount * o.quantity) AS total_value FROM orders o JOIN sales s ON o.product_id = s.id GROUP BY o.customer_id HAVING total_value > 2000;" }, { "id": "q25", "title": "Products ordered by multiple customers", "difficulty": "Advanced", "description": "Find products that have been ordered by more than one distinct customer.", "hint": "Join sales and orders, use COUNT and DISTINCT on customer_id, and group by product.", "expected_sql": "SELECT s.product_name, COUNT(DISTINCT o.customer_id) AS customer_count FROM sales s JOIN orders o ON s.id = o.product_id GROUP BY s.product_name HAVING customer_count > 1;" }, { "id": "q26", "title": "Revenue contribution by category", "difficulty": "Advanced", "description": "Calculate the total revenue (sale_amount * quantity) for each product category.", "hint": "Join tables, multiply sale_amount by quantity, and group by category.", "expected_sql": "SELECT s.category, SUM(s.sale_amount * o.quantity) AS total_revenue FROM sales s JOIN orders o ON s.id = o.product_id GROUP BY s.category;" }, { "id": "q27", "title": "Earliest and latest order per customer", "difficulty": "Advanced", "description": "Show the earliest and latest order dates for each customer.", "hint": "Use MIN and MAX on order_date, grouped by customer_id.", "expected_sql": "SELECT customer_id, MIN(order_date) AS earliest_order, MAX(order_date) AS latest_order FROM orders GROUP BY customer_id;" }, { "id": "q28", "title": "Products with high total quantity", "difficulty": "Advanced", "description": "Find products with a total ordered quantity greater than 2.", "hint": "Join sales and orders, group by product, and use HAVING clause.", "expected_sql": "SELECT s.product_name, SUM(o.quantity) AS total_quantity FROM sales s JOIN orders o ON s.id = o.product_id GROUP BY s.product_name HAVING total_quantity > 2;" }, { "id": "q29", "title": "Customers who ordered all electronics", "difficulty": "Advanced", "description": "List customers who have ordered every product in the Electronics category.", "hint": "Count distinct Electronics products per customer and compare with total Electronics products.", "expected_sql": "SELECT o.customer_id FROM orders o JOIN sales s ON o.product_id = s.id WHERE s.category = 'Electronics' GROUP BY o.customer_id HAVING COUNT(DISTINCT s.id) = (SELECT COUNT(*) FROM sales WHERE category = 'Electronics');" }, { "id": "q30", "title": "Most frequent customer by product", "difficulty": "Advanced", "description": "Find the customer who ordered each product the most times.", "hint": "Join tables, group by product and customer, use subquery to find max orders.", "expected_sql": "SELECT s.product_name, o.customer_id, COUNT(o.order_id) AS order_count FROM sales s JOIN orders o ON s.id = o.product_id GROUP BY s.product_name, o.customer_id HAVING COUNT(o.order_id) = (SELECT MAX(order_count) FROM (SELECT COUNT(order_id) AS order_count FROM orders o2 WHERE o2.product_id = s.id GROUP BY o2.customer_id) AS counts);" } ]