P-Karthik-Mohan commited on
Commit
a752355
·
1 Parent(s): c915835

Fix task 8 answer query to match agent output exactly

Browse files
Files changed (1) hide show
  1. main.py +13 -19
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
- WITH half_year AS (
206
- SELECT c.customer_id,
207
- c.first_name,
208
- c.last_name,
209
- ROUND(SUM(CASE
210
- WHEN STRFTIME('%m', o.order_date) BETWEEN '01' AND '06'
211
- THEN o.total_amount ELSE 0 END), 2) AS h1_revenue,
212
- ROUND(SUM(CASE
213
- WHEN STRFTIME('%m', o.order_date) BETWEEN '07' AND '12'
214
- THEN o.total_amount ELSE 0 END), 2) AS h2_revenue
215
- FROM orders o
216
- JOIN customers c ON o.customer_id = c.customer_id
217
- WHERE o.status = 'completed'
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
  },