File size: 3,608 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 | /*
{
"qid": "009",
"task_type": "ambig",
"has_intended_resolution": true,
"language": "SQLite",
"db": "retails",
"question": "List the customer who made the highest number of purchases using rail shipping.",
"gold_ambiguity_points": [
{
"id": "A",
"phrase": "number of purchases using rail shipping",
"type": "finite",
"ambiguity_type": "semantic_computation",
"interpretations": [
"number of orders containing at least one line item shipped by rail",
"number of line items shipped by rail",
"total quantity shipped by rail"
],
"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": [
1
],
"required_sorted": false,
"extra_info": {
"ambiguity_resolution": {
"[A] number of purchases using rail shipping": "number of orders containing at least one line item shipped by rail"
}
}
}
*/
WITH customer_rail_orders AS (
SELECT c.c_custkey,
c.c_name,
COUNT(DISTINCT o.o_orderkey) AS rail_orders
FROM customer c
JOIN orders o ON c.c_custkey = o.o_custkey
JOIN lineitem l ON o.o_orderkey = l.l_orderkey
WHERE l.l_shipmode = 'RAIL'
GROUP BY c.c_custkey, c.c_name
)
SELECT c.c_custkey, c.c_name, c.rail_orders
FROM customer_rail_orders c
WHERE c.rail_orders = (
SELECT MAX(rail_orders) FROM customer_rail_orders
);
/* EXEC RESULT
c_custkey c_name rail_orders
63035 Customer#000063035 20
68513 Customer#000068513 20
*/
----- 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
],
"required_sorted": false,
"extra_info": {
"ambiguity_resolution": {
"[A] number of purchases using rail shipping": "number of line items shipped by rail"
}
}
}
*/
WITH customer_rail_lineitems AS (
SELECT c.c_custkey,
c.c_name,
COUNT(*) AS rail_ship_count
FROM customer c
JOIN orders o ON c.c_custkey = o.o_custkey
JOIN lineitem l ON o.o_orderkey = l.l_orderkey
WHERE l.l_shipmode = 'RAIL'
GROUP BY c.c_custkey, c.c_name
)
SELECT c.c_custkey, c.c_name, c.rail_ship_count
FROM customer_rail_lineitems c
WHERE c.rail_ship_count = (
SELECT MAX(rail_ship_count) FROM customer_rail_lineitems
);
/* EXEC RESULT
c_custkey c_name rail_ship_count
63035 Customer#000063035 28
*/
----- END OF GOLD QUERY -----
----- START OF GOLD QUERY `GQRY-A.2` -----
/*
{
"id": "GQRY-A.2",
"parameter_names": [],
"parameter_values": {},
"other_exec_results": [],
"required_columns": [
1
],
"required_sorted": false,
"extra_info": {
"ambiguity_resolution": {
"[A] number of purchases using rail shipping": "total quantity shipped by rail"
}
}
}
*/
WITH customer_rail_quantity AS (
SELECT c.c_custkey,
c.c_name,
SUM(l.l_quantity) AS total_rail_quantity
FROM customer c
JOIN orders o ON c.c_custkey = o.o_custkey
JOIN lineitem l ON o.o_orderkey = l.l_orderkey
WHERE l.l_shipmode = 'RAIL'
GROUP BY c.c_custkey, c.c_name
)
SELECT c.c_custkey, c.c_name, c.total_rail_quantity
FROM customer_rail_quantity c
WHERE c.total_rail_quantity = (
SELECT MAX(total_rail_quantity) FROM customer_rail_quantity
);
/* EXEC RESULT
c_custkey c_name total_rail_quantity
119483 Customer#000119483 798
*/
----- END OF GOLD QUERY ----- |