File size: 3,337 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
/*
{
  "qid": "006",
  "task_type": "ambig",
  "has_intended_resolution": true,
  "language": "SQLite",
  "db": "retails",
  "question": "Count number of suppliers with negative balance or located in Africa and do not supply Brand#32.",
  "gold_ambiguity_points": [
    {
      "id": "A",
      "phrase": "with negative balance or located in Africa and do not supply Brand#32",
      "type": "finite",
      "ambiguity_type": "syntactic_computation",
      "interpretations": [
        "suppliers (with negative balance) OR (located in Africa AND do not supply Brand#32)",
        "suppliers (with negative balance OR located in Africa) AND (do not supply Brand#32)"
      ],
      "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": null,
  "required_sorted": false,
  "extra_info": {
    "ambiguity_resolution": {
      "[A] with negative balance or located in Africa and do not supply Brand#32": "suppliers (with negative balance) OR (located in Africa AND do not supply Brand#32)"
    }
  }
}
*/
WITH negative_balance_suppliers AS (
SELECT s.s_suppkey
FROM supplier s
WHERE s.s_acctbal < 0
)
, africa_suppliers AS (
SELECT DISTINCT s.s_suppkey
FROM supplier s
JOIN nation n ON s.s_nationkey = n.n_nationkey
JOIN region r ON n.n_regionkey = r.r_regionkey
WHERE r.r_name = 'AFRICA'
)
, brand_32_suppliers AS (
SELECT DISTINCT s.s_suppkey
FROM supplier s
JOIN partsupp ps ON s.s_suppkey = ps.ps_suppkey
JOIN part p ON ps.ps_partkey = p.p_partkey
WHERE p.p_brand = 'Brand#32'
)
SELECT COUNT(DISTINCT s.s_suppkey)
FROM supplier s
WHERE s.s_suppkey IN (SELECT s_suppkey FROM negative_balance_suppliers)
OR (
s.s_suppkey IN (SELECT s_suppkey FROM africa_suppliers)
AND s.s_suppkey NOT IN (SELECT s_suppkey FROM brand_32_suppliers)
);
/* EXEC RESULT
 COUNT(DISTINCT s.s_suppkey)
                         998
*/
----- END OF GOLD QUERY -----


----- START OF GOLD QUERY `GQRY-A.1` -----
/*
{
  "id": "GQRY-A.1",
  "parameter_names": [],
  "parameter_values": {},
  "other_exec_results": [],
  "required_columns": null,
  "required_sorted": false,
  "extra_info": {
    "ambiguity_resolution": {
      "[A] with negative balance or located in Africa and do not supply Brand#32": "suppliers (with negative balance OR located in Africa) AND (do not supply Brand#32)"
    }
  }
}
*/
WITH negative_balance_suppliers AS (
SELECT s.s_suppkey
FROM supplier s
WHERE s.s_acctbal < 0
)
, africa_suppliers AS (
SELECT DISTINCT s.s_suppkey
FROM supplier s
JOIN nation n ON s.s_nationkey = n.n_nationkey
JOIN region r ON n.n_regionkey = r.r_regionkey
WHERE r.r_name = 'AFRICA'
)
, brand_32_suppliers AS (
SELECT DISTINCT s.s_suppkey
FROM supplier s
JOIN partsupp ps ON s.s_suppkey = ps.ps_suppkey
JOIN part p ON ps.ps_partkey = p.p_partkey
WHERE p.p_brand = 'Brand#32'
)
SELECT COUNT(DISTINCT s.s_suppkey)
FROM supplier s
WHERE (
s.s_suppkey IN (SELECT s_suppkey FROM negative_balance_suppliers)
OR
s.s_suppkey IN (SELECT s_suppkey FROM africa_suppliers)
) AND s.s_suppkey NOT IN (SELECT s_suppkey FROM brand_32_suppliers);
/* EXEC RESULT
 COUNT(DISTINCT s.s_suppkey)
                         124
*/
----- END OF GOLD QUERY -----