File size: 4,384 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
/*
{
  "qid": "023",
  "task_type": "ambig",
  "has_intended_resolution": true,
  "language": "SQLite",
  "db": "retails",
  "question": "For each supplier with ID from 1 to 100, determine the total amount owed to them.",
  "gold_ambiguity_points": [
    {
      "id": "A",
      "phrase": "total amount owed",
      "type": "finite",
      "ambiguity_type": "semantic_computation",
      "interpretations": [
        "balance in the supplier's account",
        "value of open line items",
        "value of line items in unfinished orders"
      ],
      "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] total amount owed": "balance in the supplier's account"
    }
  }
}
*/
SELECT s_suppkey,
s_name,
s_acctbal AS total_amount_owed
FROM supplier
WHERE s_suppkey BETWEEN 1 AND 100;
/* EXEC RESULT
 s_suppkey             s_name  total_amount_owed
         1 Supplier#000000001            3082.86
         2 Supplier#000000002            3009.73
         3 Supplier#000000003            9159.78
         4 Supplier#000000004            9846.01
         5 Supplier#000000005             -74.94
... TRUNCATED ...
        96 Supplier#000000096            -668.13
        97 Supplier#000000097            3229.29
        98 Supplier#000000098             150.70
        99 Supplier#000000099            2074.00
       100 Supplier#000000100            1026.74
*/
----- 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] total amount owed": "value of open line items"
    }
  }
}
*/
SELECT s.s_suppkey,
s.s_name,
COALESCE(SUM(l.l_quantity * ps.ps_supplycost), 0) AS total_amount_owed
FROM supplier s
LEFT JOIN lineitem l ON s.s_suppkey = l.l_suppkey AND l.l_linestatus = 'O'
LEFT JOIN partsupp ps ON l.l_partkey = ps.ps_partkey AND l.l_suppkey = ps.ps_suppkey
WHERE s.s_suppkey BETWEEN 1 AND 100
GROUP BY s.s_suppkey, s.s_name;
/* EXEC RESULT
 s_suppkey             s_name  total_amount_owed
         1 Supplier#000000001         3997515.97
         2 Supplier#000000002         3702069.16
         3 Supplier#000000003         3821614.42
         4 Supplier#000000004         4106842.46
         5 Supplier#000000005         3237869.22
... TRUNCATED ...
        96 Supplier#000000096         3946293.81
        97 Supplier#000000097         5186666.95
        98 Supplier#000000098         4234214.40
        99 Supplier#000000099         3389696.31
       100 Supplier#000000100         2705119.05
*/
----- 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] total amount owed": "value of line items in unfinished orders"
    }
  }
}
*/
SELECT s.s_suppkey,
s.s_name,
COALESCE(SUM(l.l_quantity * ps.ps_supplycost), 0) AS total_amount_owed
FROM supplier AS s
LEFT JOIN lineitem AS l ON s.s_suppkey = l.l_suppkey
LEFT JOIN partsupp AS ps ON l.l_partkey = ps.ps_partkey AND l.l_suppkey = ps.ps_suppkey
LEFT JOIN orders AS o ON l.l_orderkey = o.o_orderkey AND o.o_orderstatus <> 'F'
WHERE s.s_suppkey BETWEEN 1 AND 100
GROUP BY s.s_suppkey, s.s_name;
/* EXEC RESULT
 s_suppkey             s_name  total_amount_owed
         1 Supplier#000000001         6214813.11
         2 Supplier#000000002         5173401.67
         3 Supplier#000000003         5582552.23
         4 Supplier#000000004         5775465.02
         5 Supplier#000000005         4846809.88
... TRUNCATED ...
        96 Supplier#000000096         5815827.40
        97 Supplier#000000097         7649457.28
        98 Supplier#000000098         6310857.48
        99 Supplier#000000099         5039484.14
       100 Supplier#000000100         4159018.36
*/
----- END OF GOLD QUERY -----