| /* | |
| { | |
| "qid": "014", | |
| "task_type": "ambig", | |
| "has_intended_resolution": true, | |
| "language": "SQLite", | |
| "db": "retails", | |
| "question": "Show the supplier that supplies the most parts in their inventory in each region.", | |
| "gold_ambiguity_points": [ | |
| { | |
| "id": "A", | |
| "phrase": "supplies the most parts", | |
| "type": "finite", | |
| "ambiguity_type": "semantic_computation", | |
| "interpretations": [ | |
| "supplies the largest number of distinct parts", | |
| "supplies the largest total inventory quantity" | |
| ], | |
| "intended_interpretation_idx": 0 | |
| } | |
| ], | |
| "gold_intended_query_id": "GQRY-A.0", | |
| "extra_info": {} | |
| } | |
| */ | |
| ----- START OF GOLD QUERY `GQRY-A.0` ----- | |
| /* | |
| { | |
| "id": "GQRY-A.0", | |
| "parameter_names": [], | |
| "parameter_values": {}, | |
| "other_exec_results": [], | |
| "required_columns": [ | |
| 1, | |
| 3 | |
| ], | |
| "required_sorted": false, | |
| "extra_info": { | |
| "ambiguity_resolution": { | |
| "[A] supplies the most parts": "supplies the largest number of distinct parts" | |
| } | |
| } | |
| } | |
| */ | |
| WITH supplier_part_count AS ( | |
| SELECT r.r_regionkey AS region_key, | |
| r.r_name AS region_name, | |
| s.s_suppkey, | |
| s.s_name, | |
| COUNT(DISTINCT ps.ps_partkey) AS total_quantity, | |
| RANK() OVER (PARTITION BY r.r_regionkey ORDER BY COUNT(DISTINCT ps.ps_partkey) DESC) AS rn | |
| FROM supplier s | |
| JOIN nation n ON s.s_nationkey = n.n_nationkey | |
| JOIN region r ON n.n_regionkey = r.r_regionkey | |
| JOIN partsupp ps ON s.s_suppkey = ps.ps_suppkey | |
| GROUP BY r.r_regionkey, r.r_name, s.s_suppkey, s.s_name | |
| ) | |
| SELECT region_key, region_name, s_suppkey, s_name, total_quantity | |
| FROM supplier_part_count | |
| WHERE rn = 1; | |
| /* EXEC RESULT | |
| region_key region_name s_suppkey s_name total_quantity | |
| 0 AFRICA 2 Supplier#000000002 80 | |
| 0 AFRICA 7 Supplier#000000007 80 | |
| 0 AFRICA 8 Supplier#000000008 80 | |
| 0 AFRICA 21 Supplier#000000021 80 | |
| 0 AFRICA 22 Supplier#000000022 80 | |
| ... TRUNCATED ... | |
| 4 MIDDLE EAST 9989 Supplier#000009989 80 | |
| 4 MIDDLE EAST 9991 Supplier#000009991 80 | |
| 4 MIDDLE EAST 9992 Supplier#000009992 80 | |
| 4 MIDDLE EAST 9994 Supplier#000009994 80 | |
| 4 MIDDLE EAST 9996 Supplier#000009996 80 | |
| */ | |
| ----- END OF GOLD QUERY ----- | |
| ----- START OF GOLD QUERY `GQRY-A.1` ----- | |
| /* | |
| { | |
| "id": "GQRY-A.1", | |
| "parameter_names": [], | |
| "parameter_values": {}, | |
| "other_exec_results": [], | |
| "required_columns": [ | |
| 1, | |
| 3 | |
| ], | |
| "required_sorted": false, | |
| "extra_info": { | |
| "ambiguity_resolution": { | |
| "[A] supplies the most parts": "supplies the largest total inventory quantity" | |
| } | |
| } | |
| } | |
| */ | |
| WITH supplier_part_count AS ( | |
| SELECT r.r_regionkey AS region_key, | |
| r.r_name AS region_name, | |
| s.s_suppkey, | |
| s.s_name, | |
| SUM(ps.ps_availqty) AS total_quantity, | |
| RANK() OVER (PARTITION BY r.r_regionkey ORDER BY SUM(ps.ps_availqty) DESC) AS rn | |
| FROM supplier s | |
| JOIN nation n ON s.s_nationkey = n.n_nationkey | |
| JOIN region r ON n.n_regionkey = r.r_regionkey | |
| JOIN partsupp ps ON s.s_suppkey = ps.ps_suppkey | |
| GROUP BY r.r_regionkey, r.r_name, s.s_suppkey, s.s_name | |
| ) | |
| SELECT region_key, region_name, s_suppkey, s_name, total_quantity | |
| FROM supplier_part_count | |
| WHERE rn = 1; | |
| /* EXEC RESULT | |
| region_key region_name s_suppkey s_name total_quantity | |
| 0 AFRICA 4296 Supplier#000004296 482324 | |
| 1 AMERICA 7546 Supplier#000007546 501179 | |
| 2 ASIA 6337 Supplier#000006337 490915 | |
| 3 EUROPE 1270 Supplier#000001270 521832 | |
| 4 MIDDLE EAST 9411 Supplier#000009411 484402 | |
| */ | |
| ----- END OF GOLD QUERY ----- |