File size: 11,519 Bytes
e7cf806 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
[
{
"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);"
}
]
|