File size: 3,731 Bytes
02edc38 | 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 | /*
{
"qid": "022",
"task_type": "ambig",
"has_intended_resolution": true,
"language": "SQLite",
"db": "retails",
"question": "Show the customer with the highest account balance for each area.",
"gold_ambiguity_points": [
{
"id": "A",
"phrase": "area",
"type": "finite",
"ambiguity_type": "semantic_column",
"interpretations": [
"nation",
"region",
"market segment"
],
"intended_interpretation_idx": 2
}
],
"gold_intended_query_id": "GQRY-A.2",
"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] area": "nation"
}
}
}
*/
SELECT n_name, c_custkey, c_name, c_acctbal
FROM (
SELECT n.n_nationkey,
n.n_name,
c.c_custkey,
c.c_name,
c.c_acctbal,
RANK() OVER (PARTITION BY n.n_nationkey ORDER BY c.c_acctbal DESC) AS rn
FROM customer c
JOIN nation n ON c.c_nationkey = n.n_nationkey
) t
WHERE rn = 1;
/* EXEC RESULT
n_name c_custkey c_name c_acctbal
ALGERIA 122154 Customer#000122154 9999.60
ARGENTINA 14740 Customer#000014740 9999.96
BRAZIL 21734 Customer#000021734 9998.72
CANADA 147958 Customer#000147958 9998.59
EGYPT 124581 Customer#000124581 9996.59
... TRUNCATED ...
SAUDI ARABIA 105511 Customer#000105511 9995.57
VIETNAM 330 Customer#000000330 9999.59
RUSSIA 81836 Customer#000081836 9997.92
UNITED KINGDOM 113195 Customer#000113195 9995.65
UNITED STATES 75730 Customer#000075730 9999.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": [
0,
2
],
"required_sorted": false,
"extra_info": {
"ambiguity_resolution": {
"[A] area": "region"
}
}
}
*/
SELECT r_name, c_custkey, c_name, c_acctbal
FROM (
SELECT r.r_regionkey,
r.r_name,
c.c_custkey,
c.c_name,
c.c_acctbal,
RANK() OVER (PARTITION BY r.r_regionkey ORDER BY c.c_acctbal DESC) AS rn
FROM customer c
JOIN nation n ON c.c_nationkey = n.n_nationkey
JOIN region r ON n.n_regionkey = r.r_regionkey
) t
WHERE rn = 1;
/* EXEC RESULT
r_name c_custkey c_name c_acctbal
AFRICA 118127 Customer#000118127 9999.94
AMERICA 14740 Customer#000014740 9999.96
ASIA 73836 Customer#000073836 9999.75
EUROPE 97961 Customer#000097961 9999.56
MIDDLE EAST 72823 Customer#000072823 9999.65
*/
----- END OF GOLD QUERY -----
----- START OF GOLD QUERY `GQRY-A.2` -----
/*
{
"id": "GQRY-A.2",
"parameter_names": [],
"parameter_values": {},
"other_exec_results": [],
"required_columns": [
0,
2
],
"required_sorted": false,
"extra_info": {
"ambiguity_resolution": {
"[A] area": "market segment"
}
}
}
*/
SELECT c_mktsegment, c_custkey, c_name, c_acctbal
FROM (
SELECT c.c_mktsegment,
c.c_custkey,
c.c_name,
c.c_acctbal,
RANK() OVER (PARTITION BY c.c_mktsegment ORDER BY c.c_acctbal DESC) AS rn
FROM customer c
) t
WHERE rn = 1;
/* EXEC RESULT
c_mktsegment c_custkey c_name c_acctbal
AUTOMOBILE 21734 Customer#000021734 9998.72
BUILDING 330 Customer#000000330 9999.59
FURNITURE 72823 Customer#000072823 9999.65
HOUSEHOLD 48616 Customer#000048616 9999.84
MACHINERY 14740 Customer#000014740 9999.96
*/
----- END OF GOLD QUERY ----- |