/* { "qid": "017", "task_type": "ambig", "has_intended_resolution": true, "language": "SQLite", "db": "retails", "question": "Find the customer with the largest order value in each market segment.", "gold_ambiguity_points": [ { "id": "A", "phrase": "largest order value", "type": "finite", "ambiguity_type": "semantic_computation", "interpretations": [ "largest single order value", "largest total order value" ], "intended_interpretation_idx": 1 } ], "gold_intended_query_id": "GQRY-A.1", "extra_info": {} } */ ----- START OF GOLD QUERY `GQRY-A.0` ----- /* { "id": "GQRY-A.0", "parameter_names": [], "parameter_values": {}, "other_exec_results": [], "required_columns": [ 0, 2 ], "required_sorted": false, "extra_info": { "ambiguity_resolution": { "[A] largest order value": "largest single order value" } } } */ WITH order_totals AS ( SELECT c_mktsegment, c.c_custkey, c.c_name, MAX(o.o_totalprice) AS max_o_totalprice FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey GROUP BY c_mktsegment, c.c_custkey, c.c_name ) SELECT ot.c_mktsegment AS market_segment, ot.c_custkey AS customer_key, ot.c_name AS customer_name, ot.max_o_totalprice AS largest_value FROM order_totals ot JOIN ( SELECT ot2.c_mktsegment, MAX(ot2.max_o_totalprice) AS max_value FROM order_totals ot2 GROUP BY ot2.c_mktsegment ) AS max_val ON ot.c_mktsegment = max_val.c_mktsegment AND ot.max_o_totalprice = max_val.max_value; /* EXEC RESULT market_segment customer_key customer_name largest_value AUTOMOBILE 92176 Customer#000092176 516410.40 BUILDING 20210 Customer#000020210 528557.33 FURNITURE 62623 Customer#000062623 527130.81 HOUSEHOLD 122104 Customer#000122104 499669.03 MACHINERY 126544 Customer#000126544 510600.98 */ ----- END OF GOLD QUERY ----- ----- START OF GOLD QUERY `GQRY-A.1` ----- /* { "id": "GQRY-A.1", "parameter_names": [], "parameter_values": {}, "other_exec_results": [], "required_columns": [ 0, 2 ], "required_sorted": false, "extra_info": { "ambiguity_resolution": { "[A] largest order value": "largest total order value" } } } */ WITH order_totals AS ( SELECT c_mktsegment, c.c_custkey, c.c_name, SUM(o.o_totalprice) AS total_o_totalprice FROM customer c JOIN orders o ON c.c_custkey = o.o_custkey GROUP BY c_mktsegment, c.c_custkey, c.c_name ) SELECT ot.c_mktsegment AS market_segment, ot.c_custkey AS customer_key, ot.c_name AS customer_name, ot.total_o_totalprice AS largest_value FROM order_totals ot JOIN ( SELECT ot2.c_mktsegment, MAX(ot2.total_o_totalprice) AS max_value FROM order_totals ot2 GROUP BY ot2.c_mktsegment ) AS max_val ON ot.c_mktsegment = max_val.c_mktsegment AND ot.total_o_totalprice = max_val.max_value; /* EXEC RESULT market_segment customer_key customer_name largest_value AUTOMOBILE 114308 Customer#000114308 5486668.76 BUILDING 58421 Customer#000058421 5487155.77 FURNITURE 41290 Customer#000041290 5473361.71 HOUSEHOLD 79933 Customer#000079933 5928489.38 MACHINERY 58387 Customer#000058387 5719569.38 */ ----- END OF GOLD QUERY -----