You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started/example-datasets/tpch.md
+137-6Lines changed: 137 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -234,7 +234,7 @@ ORDER BY
234
234
**Q2**
235
235
236
236
```sql
237
-
SET allow_experimental_correlated_subqueries = 1;
237
+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
238
238
239
239
SELECT
240
240
s_acctbal,
@@ -281,6 +281,62 @@ ORDER BY
281
281
p_partkey;
282
282
```
283
283
284
+
::::note
285
+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
286
+
287
+
This alternative formulation works and was verified to return the reference results.
288
+
289
+
```sql
290
+
WITH MinSupplyCost AS (
291
+
SELECT
292
+
ps_partkey,
293
+
MIN(ps_supplycost) AS min_supplycost
294
+
FROM
295
+
partsupp ps
296
+
JOIN
297
+
supplier s ON ps.ps_suppkey = s.s_suppkey
298
+
JOIN
299
+
nation n ON s.s_nationkey = n.n_nationkey
300
+
JOIN
301
+
region r ON n.n_regionkey = r.r_regionkey
302
+
WHERE
303
+
r.r_name = 'EUROPE'
304
+
GROUP BY
305
+
ps_partkey
306
+
)
307
+
SELECT
308
+
s.s_acctbal,
309
+
s.s_name,
310
+
n.n_name,
311
+
p.p_partkey,
312
+
p.p_mfgr,
313
+
s.s_address,
314
+
s.s_phone,
315
+
s.s_comment
316
+
FROM
317
+
part p
318
+
JOIN
319
+
partsupp ps ON p.p_partkey = ps.ps_partkey
320
+
JOIN
321
+
supplier s ON s.s_suppkey = ps.ps_suppkey
322
+
JOIN
323
+
nation n ON s.s_nationkey = n.n_nationkey
324
+
JOIN
325
+
region r ON n.n_regionkey = r.r_regionkey
326
+
JOIN
327
+
MinSupplyCost msc ON ps.ps_partkey = msc.ps_partkey AND ps.ps_supplycost = msc.min_supplycost
328
+
WHERE
329
+
p.p_size = 15
330
+
AND p.p_type LIKE '%BRASS'
331
+
AND r.r_name = 'EUROPE'
332
+
ORDER BY
333
+
s.s_acctbal DESC,
334
+
n.n_name,
335
+
s.s_name,
336
+
p.p_partkey;
337
+
```
338
+
::::
339
+
284
340
**Q3**
285
341
286
342
```sql
@@ -311,7 +367,7 @@ ORDER BY
311
367
**Q4**
312
368
313
369
```sql
314
-
SET allow_experimental_correlated_subqueries = 1;
370
+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
315
371
316
372
SELECT
317
373
o_orderpriority,
@@ -336,6 +392,39 @@ ORDER BY
336
392
o_orderpriority;
337
393
```
338
394
395
+
::::note
396
+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
397
+
398
+
This alternative formulation works and was verified to return the reference results.
399
+
400
+
```sql
401
+
WITH ValidLineItems AS (
402
+
SELECT
403
+
l_orderkey
404
+
FROM
405
+
lineitem
406
+
WHERE
407
+
l_commitdate < l_receiptdate
408
+
GROUP BY
409
+
l_orderkey
410
+
)
411
+
SELECT
412
+
o.o_orderpriority,
413
+
COUNT(*) AS order_count
414
+
FROM
415
+
orders o
416
+
JOIN
417
+
ValidLineItems vli ON o.o_orderkey = vli.l_orderkey
418
+
WHERE
419
+
o.o_orderdate >= DATE '1993-07-01'
420
+
AND o.o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH
421
+
GROUP BY
422
+
o.o_orderpriority
423
+
ORDER BY
424
+
o.o_orderpriority;
425
+
```
426
+
::::
427
+
339
428
**Q5**
340
429
341
430
```sql
@@ -738,7 +827,7 @@ ORDER BY
738
827
**Q17**
739
828
740
829
```sql
741
-
SET allow_experimental_correlated_subqueries = 1;
830
+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
742
831
743
832
SELECT
744
833
sum(l_extendedprice) / 7.0 AS avg_yearly
@@ -759,6 +848,37 @@ WHERE
759
848
);
760
849
```
761
850
851
+
::::note
852
+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
853
+
854
+
This alternative formulation works and was verified to return the reference results.
855
+
856
+
```sql
857
+
WITH AvgQuantity AS (
858
+
SELECT
859
+
l_partkey,
860
+
AVG(l_quantity) * 0.2 AS avg_quantity
861
+
FROM
862
+
lineitem
863
+
GROUP BY
864
+
l_partkey
865
+
)
866
+
SELECT
867
+
SUM(l.l_extendedprice) / 7.0 AS avg_yearly
868
+
FROM
869
+
lineitem l
870
+
JOIN
871
+
part p ON p.p_partkey = l.l_partkey
872
+
JOIN
873
+
AvgQuantity aq ON l.l_partkey = aq.l_partkey
874
+
WHERE
875
+
p.p_brand = 'Brand#23'
876
+
AND p.p_container = 'MED BOX'
877
+
AND l.l_quantity < aq.avg_quantity;
878
+
879
+
```
880
+
::::
881
+
762
882
**Q18**
763
883
764
884
```sql
@@ -840,7 +960,7 @@ WHERE
840
960
**Q20**
841
961
842
962
```sql
843
-
SET allow_experimental_correlated_subqueries = 1;
963
+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
844
964
845
965
SELECT
846
966
s_name,
@@ -881,10 +1001,14 @@ ORDER BY
881
1001
s_name;
882
1002
```
883
1003
1004
+
::::note
1005
+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1006
+
::::
1007
+
884
1008
**Q21**
885
1009
886
1010
```sql
887
-
SET allow_experimental_correlated_subqueries = 1;
1011
+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
888
1012
889
1013
SELECT
890
1014
s_name,
@@ -926,11 +1050,14 @@ ORDER BY
926
1050
numwait DESC,
927
1051
s_name;
928
1052
```
1053
+
::::note
1054
+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1055
+
::::
929
1056
930
1057
**Q22**
931
1058
932
1059
```sql
933
-
SET allow_experimental_correlated_subqueries = 1;
1060
+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
934
1061
935
1062
SELECT
936
1063
cntrycode,
@@ -969,3 +1096,7 @@ GROUP BY
969
1096
ORDER BY
970
1097
cntrycode;
971
1098
```
1099
+
1100
+
::::note
1101
+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
0 commit comments