Spaces:
Sleeping
Sleeping
Commit ·
a752355
1
Parent(s): c915835
Fix task 8 answer query to match agent output exactly
Browse files
main.py
CHANGED
|
@@ -202,25 +202,19 @@ TASKS = {
|
|
| 202 |
"difficulty": "expert",
|
| 203 |
"hint": "Use conditional SUM with CASE WHEN to split spending by half-year, then filter WHERE h2 > h1",
|
| 204 |
"answer_query": """
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
AND o.order_date LIKE '2024%'
|
| 219 |
-
GROUP BY c.customer_id
|
| 220 |
-
)
|
| 221 |
-
SELECT customer_id, first_name, last_name, h1_revenue, h2_revenue
|
| 222 |
-
FROM half_year
|
| 223 |
-
WHERE h2_revenue > h1_revenue
|
| 224 |
ORDER BY h2_revenue DESC
|
| 225 |
""",
|
| 226 |
},
|
|
|
|
| 202 |
"difficulty": "expert",
|
| 203 |
"hint": "Use conditional SUM with CASE WHEN to split spending by half-year, then filter WHERE h2 > h1",
|
| 204 |
"answer_query": """
|
| 205 |
+
SELECT c.customer_id,
|
| 206 |
+
c.first_name,
|
| 207 |
+
c.last_name,
|
| 208 |
+
SUM(CASE WHEN STRFTIME('%m', o.order_date) BETWEEN '01' AND '06'
|
| 209 |
+
THEN o.total_amount ELSE 0 END) AS h1_revenue,
|
| 210 |
+
SUM(CASE WHEN STRFTIME('%m', o.order_date) BETWEEN '07' AND '12'
|
| 211 |
+
THEN o.total_amount ELSE 0 END) AS h2_revenue
|
| 212 |
+
FROM orders o
|
| 213 |
+
JOIN customers c ON o.customer_id = c.customer_id
|
| 214 |
+
WHERE o.status = 'completed'
|
| 215 |
+
AND o.order_date LIKE '2024%'
|
| 216 |
+
GROUP BY c.customer_id
|
| 217 |
+
HAVING h2_revenue > h1_revenue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
ORDER BY h2_revenue DESC
|
| 219 |
""",
|
| 220 |
},
|