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
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
284
-
285
-
This alternative formulation works and was verified to return the reference results.
286
-
287
-
```sql
288
-
WITH MinSupplyCost AS (
289
-
SELECT
290
-
ps_partkey,
291
-
MIN(ps_supplycost) AS min_supplycost
292
-
FROM
293
-
partsupp ps
294
-
JOIN
295
-
supplier s ON ps.ps_suppkey = s.s_suppkey
296
-
JOIN
297
-
nation n ON s.s_nationkey = n.n_nationkey
298
-
JOIN
299
-
region r ON n.n_regionkey = r.r_regionkey
300
-
WHERE
301
-
r.r_name = 'EUROPE'
302
-
GROUP BY
303
-
ps_partkey
304
-
)
305
-
SELECT
306
-
s.s_acctbal,
307
-
s.s_name,
308
-
n.n_name,
309
-
p.p_partkey,
310
-
p.p_mfgr,
311
-
s.s_address,
312
-
s.s_phone,
313
-
s.s_comment
314
-
FROM
315
-
part p
316
-
JOIN
317
-
partsupp ps ON p.p_partkey = ps.ps_partkey
318
-
JOIN
319
-
supplier s ON s.s_suppkey = ps.ps_suppkey
320
-
JOIN
321
-
nation n ON s.s_nationkey = n.n_nationkey
322
-
JOIN
323
-
region r ON n.n_regionkey = r.r_regionkey
324
-
JOIN
325
-
MinSupplyCost msc ON ps.ps_partkey = msc.ps_partkey AND ps.ps_supplycost = msc.min_supplycost
326
-
WHERE
327
-
p.p_size = 15
328
-
AND p.p_type LIKE '%BRASS'
329
-
AND r.r_name = 'EUROPE'
330
-
ORDER BY
331
-
s.s_acctbal DESC,
332
-
n.n_name,
333
-
s.s_name,
334
-
p.p_partkey;
335
-
```
336
-
::::
337
-
338
284
**Q3**
339
285
340
286
```sql
@@ -365,6 +311,8 @@ ORDER BY
365
311
**Q4**
366
312
367
313
```sql
314
+
SET allow_experimental_correlated_subqueries = 1;
315
+
368
316
SELECT
369
317
o_orderpriority,
370
318
count(*) AS order_count
@@ -388,39 +336,6 @@ ORDER BY
388
336
o_orderpriority;
389
337
```
390
338
391
-
::::note
392
-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
393
-
394
-
This alternative formulation works and was verified to return the reference results.
395
-
396
-
```sql
397
-
WITH ValidLineItems AS (
398
-
SELECT
399
-
l_orderkey
400
-
FROM
401
-
lineitem
402
-
WHERE
403
-
l_commitdate < l_receiptdate
404
-
GROUP BY
405
-
l_orderkey
406
-
)
407
-
SELECT
408
-
o.o_orderpriority,
409
-
COUNT(*) AS order_count
410
-
FROM
411
-
orders o
412
-
JOIN
413
-
ValidLineItems vli ON o.o_orderkey = vli.l_orderkey
414
-
WHERE
415
-
o.o_orderdate >= DATE '1993-07-01'
416
-
AND o.o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH
417
-
GROUP BY
418
-
o.o_orderpriority
419
-
ORDER BY
420
-
o.o_orderpriority;
421
-
```
422
-
::::
423
-
424
339
**Q5**
425
340
426
341
```sql
@@ -823,6 +738,8 @@ ORDER BY
823
738
**Q17**
824
739
825
740
```sql
741
+
SET allow_experimental_correlated_subqueries = 1;
742
+
826
743
SELECT
827
744
sum(l_extendedprice) / 7.0 AS avg_yearly
828
745
FROM
@@ -842,37 +759,6 @@ WHERE
842
759
);
843
760
```
844
761
845
-
::::note
846
-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
847
-
848
-
This alternative formulation works and was verified to return the reference results.
849
-
850
-
```sql
851
-
WITH AvgQuantity AS (
852
-
SELECT
853
-
l_partkey,
854
-
AVG(l_quantity) * 0.2 AS avg_quantity
855
-
FROM
856
-
lineitem
857
-
GROUP BY
858
-
l_partkey
859
-
)
860
-
SELECT
861
-
SUM(l.l_extendedprice) / 7.0 AS avg_yearly
862
-
FROM
863
-
lineitem l
864
-
JOIN
865
-
part p ON p.p_partkey = l.l_partkey
866
-
JOIN
867
-
AvgQuantity aq ON l.l_partkey = aq.l_partkey
868
-
WHERE
869
-
p.p_brand = 'Brand#23'
870
-
AND p.p_container = 'MED BOX'
871
-
AND l.l_quantity < aq.avg_quantity;
872
-
873
-
```
874
-
::::
875
-
876
762
**Q18**
877
763
878
764
```sql
@@ -954,6 +840,8 @@ WHERE
954
840
**Q20**
955
841
956
842
```sql
843
+
SET allow_experimental_correlated_subqueries = 1;
844
+
957
845
SELECT
958
846
s_name,
959
847
s_address
@@ -993,13 +881,11 @@ ORDER BY
993
881
s_name;
994
882
```
995
883
996
-
::::note
997
-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
998
-
::::
999
-
1000
884
**Q21**
1001
885
1002
886
```sql
887
+
SET allow_experimental_correlated_subqueries = 1;
888
+
1003
889
SELECT
1004
890
s_name,
1005
891
count(*) AS numwait
@@ -1040,13 +926,12 @@ ORDER BY
1040
926
numwait DESC,
1041
927
s_name;
1042
928
```
1043
-
::::note
1044
-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1045
-
::::
1046
929
1047
930
**Q22**
1048
931
1049
932
```sql
933
+
SET allow_experimental_correlated_subqueries = 1;
934
+
1050
935
SELECT
1051
936
cntrycode,
1052
937
count(*) AS numcust,
@@ -1084,7 +969,3 @@ GROUP BY
1084
969
ORDER BY
1085
970
cntrycode;
1086
971
```
1087
-
1088
-
::::note
1089
-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
0 commit comments