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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
SELECT * FROM test;
SELECT
*
FROM test;
WITH a AS ((SELECT 1 AS b) UNION ALL (SELECT 2 AS b)) SELECT * FROM a;
WITH a AS (
(
SELECT
1 AS b
)
UNION ALL
(
SELECT
2 AS b
)
)
SELECT
*
FROM a;
WITH cte1 AS (
SELECT a, z and e AS b
FROM cte
WHERE x IN (1, 2, 3) AND z < -1 OR z > 1 AND w = 'AND'
), cte2 AS (
SELECT RANK() OVER (PARTITION BY a, b ORDER BY x DESC) a, b
FROM cte
CROSS JOIN (
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT CASE x AND 1 + 1 = 2
WHEN TRUE THEN 1 AND 4 + 3 AND Z
WHEN x and y THEN 2
ELSE 3 AND 4 AND g END
UNION ALL
SELECT 1
FROM (SELECT 1) AS x, y, (SELECT 2) z
UNION ALL
SELECT MAX(COALESCE(x AND y, a and b and c, d and e)), FOO(CASE WHEN a and b THEN c and d ELSE 3 END)
GROUP BY x, GROUPING SETS (a, (b, c)) CUBE(y, z)
) x
)
SELECT a, b c FROM (
SELECT a w, 1 + 1 AS c
FROM foo
WHERE w IN (SELECT z FROM q)
GROUP BY a, b
) x
LEFT JOIN (
SELECT a, b
FROM (SELECT * FROM bar WHERE (c > 1 AND d > 1) OR e > 1 GROUP BY a HAVING a > 1 LIMIT 10) z
) y ON x.a = y.b AND x.a > 1 OR (x.c = y.d OR x.c = y.e);
WITH cte1 AS (
SELECT
a,
z AND e AS b
FROM cte
WHERE
x IN (1, 2, 3) AND z < -1 OR z > 1 AND w = 'AND'
), cte2 AS (
SELECT
RANK() OVER (PARTITION BY a, b ORDER BY x DESC) AS a,
b
FROM cte
CROSS JOIN (
SELECT
1
UNION ALL
SELECT
2
UNION ALL
SELECT
CASE x AND 1 + 1 = 2
WHEN TRUE
THEN 1 AND 4 + 3 AND Z
WHEN x AND y
THEN 2
ELSE 3 AND 4 AND g
END
UNION ALL
SELECT
1
FROM (
SELECT
1
) AS x, y, (
SELECT
2
) AS z
UNION ALL
SELECT
MAX(COALESCE(x AND y, a AND b AND c, d AND e)),
FOO(CASE WHEN a AND b THEN c AND d ELSE 3 END)
GROUP BY
x
GROUPING SETS (
a,
(b, c)
)
CUBE (
y,
z
)
) AS x
)
SELECT
a,
b AS c
FROM (
SELECT
a AS w,
1 + 1 AS c
FROM foo
WHERE
w IN (
SELECT
z
FROM q
)
GROUP BY
a,
b
) AS x
LEFT JOIN (
SELECT
a,
b
FROM (
SELECT
*
FROM bar
WHERE
(
c > 1 AND d > 1
) OR e > 1
GROUP BY
a
HAVING
a > 1
LIMIT 10
) AS z
) AS y
ON x.a = y.b AND x.a > 1 OR (
x.c = y.d OR x.c = y.e
);
SELECT myCol1, myCol2 FROM baseTable LATERAL VIEW OUTER explode(col1) myTable1 AS myCol1 LATERAL VIEW explode(col2) myTable2 AS myCol2
where a > 1 and b > 2 or c > 3;
SELECT
myCol1,
myCol2
FROM baseTable
LATERAL VIEW OUTER
EXPLODE(col1) myTable1 AS myCol1
LATERAL VIEW
EXPLODE(col2) myTable2 AS myCol2
WHERE
a > 1 AND b > 2 OR c > 3;
SELECT * FROM (WITH y AS ( SELECT 1 AS z) SELECT z from y) x;
SELECT
*
FROM (
WITH y AS (
SELECT
1 AS z
)
SELECT
z
FROM y
) AS x;
INSERT OVERWRITE TABLE x VALUES (1, 2.0, '3.0'), (4, 5.0, '6.0');
INSERT OVERWRITE TABLE x VALUES
(1, 2.0, '3.0'),
(4, 5.0, '6.0');
WITH regional_sales AS (
SELECT region, SUM(amount) AS total_sales
FROM orders
GROUP BY region
), top_regions AS (
SELECT region
FROM regional_sales
WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
)
SELECT region,
product,
SUM(quantity) AS product_units,
SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;
WITH regional_sales AS (
SELECT
region,
SUM(amount) AS total_sales
FROM orders
GROUP BY
region
), top_regions AS (
SELECT
region
FROM regional_sales
WHERE
total_sales > (
SELECT
SUM(total_sales) / 10
FROM regional_sales
)
)
SELECT
region,
product,
SUM(quantity) AS product_units,
SUM(amount) AS product_sales
FROM orders
WHERE
region IN (
SELECT
region
FROM top_regions
)
GROUP BY
region,
product;
CREATE TABLE "t_customer_account" ( "id" int, "customer_id" int, "bank" varchar(100), "account_no" varchar(100));
CREATE TABLE "t_customer_account" (
"id" INT,
"customer_id" INT,
"bank" VARCHAR(100),
"account_no" VARCHAR(100)
);
SELECT
x("aaaaaaaaaaaaaa", "bbbbbbbbbbbbb", "ccccccccc", "ddddddddddddd", "eeeeeeeeeeeee", "fffffff"),
array("aaaaaaaaaaaaaa", "bbbbbbbbbbbbb", "ccccccccc", "ddddddddddddd", "eeeeeeeeeeeee", "fffffff"),
array("aaaaaaaaaaaaaa", "bbbbbbbbbbbbb", "ccccccccc", "ddddddddddddd", "eeeeeeeeeeeee", "fffffff", array("aaaaaaaaaaaaaa", "bbbbbbbbbbbbb", "ccccccccc", "ddddddddddddd", "eeeeeeeeeeeee", "fffffff")),
array(array("aaaaaaaaaaaaaa", "bbbbbbbbbbbbb", "ccccccccc", "ddddddddddddd", "eeeeeeeeeeeee", "fffffff")),
;
SELECT
X(
"aaaaaaaaaaaaaa",
"bbbbbbbbbbbbb",
"ccccccccc",
"ddddddddddddd",
"eeeeeeeeeeeee",
"fffffff"
),
ARRAY(
"aaaaaaaaaaaaaa",
"bbbbbbbbbbbbb",
"ccccccccc",
"ddddddddddddd",
"eeeeeeeeeeeee",
"fffffff"
),
ARRAY(
"aaaaaaaaaaaaaa",
"bbbbbbbbbbbbb",
"ccccccccc",
"ddddddddddddd",
"eeeeeeeeeeeee",
"fffffff",
ARRAY(
"aaaaaaaaaaaaaa",
"bbbbbbbbbbbbb",
"ccccccccc",
"ddddddddddddd",
"eeeeeeeeeeeee",
"fffffff"
)
),
ARRAY(
ARRAY(
"aaaaaaaaaaaaaa",
"bbbbbbbbbbbbb",
"ccccccccc",
"ddddddddddddd",
"eeeeeeeeeeeee",
"fffffff"
)
);
/*
multi
line
comment
*/
SELECT * FROM foo;
/*
multi
line
comment
*/
SELECT
*
FROM foo;
SELECT x FROM a.b.c /*x*/, e.f.g /*x*/;
SELECT
x
FROM a.b.c /* x */, e.f.g /* x */;
SELECT x FROM (SELECT * FROM bla /*x*/WHERE id = 1) /*x*/;
SELECT
x
FROM (
SELECT
*
FROM bla /* x */
WHERE
id = 1
) /* x */;
|