summaryrefslogtreecommitdiffstats
path: root/tests/fixtures/optimizer/optimizer.sql
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-06 07:48:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-08-06 07:48:08 +0000
commitb737ee75da2515a4a53956e41ae85e29dd67f21d (patch)
tree3896f4cac8aebc31f5cdb32a111fa801aba7ca22 /tests/fixtures/optimizer/optimizer.sql
parentAdding upstream version 17.7.0. (diff)
downloadsqlglot-b737ee75da2515a4a53956e41ae85e29dd67f21d.tar.xz
sqlglot-b737ee75da2515a4a53956e41ae85e29dd67f21d.zip
Adding upstream version 17.9.1.upstream/17.9.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/fixtures/optimizer/optimizer.sql')
-rw-r--r--tests/fixtures/optimizer/optimizer.sql19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/fixtures/optimizer/optimizer.sql b/tests/fixtures/optimizer/optimizer.sql
index 14f5cfe..981e052 100644
--- a/tests/fixtures/optimizer/optimizer.sql
+++ b/tests/fixtures/optimizer/optimizer.sql
@@ -638,7 +638,7 @@ SELECT
FROM "users" AS "u"
CROSS JOIN LATERAL (
SELECT
- "l"."log_date"
+ "l"."log_date" AS "log_date"
FROM "logs" AS "l"
WHERE
"l"."log_date" <= 100 AND "l"."user_id" = "u"."user_id"
@@ -890,3 +890,20 @@ FROM (
JOIN "y" AS "y"
ON "x"."a" = "y"."c"
);
+
+# title: replace scalar subquery, wrap resulting column in a MAX
+SELECT a, SUM(c) / (SELECT SUM(c) FROM y) * 100 AS foo FROM y INNER JOIN x ON y.b = x.b GROUP BY a;
+WITH "_u_0" AS (
+ SELECT
+ SUM("y"."c") AS "_col_0"
+ FROM "y" AS "y"
+)
+SELECT
+ "x"."a" AS "a",
+ SUM("y"."c") / MAX("_u_0"."_col_0") * 100 AS "foo"
+FROM "y" AS "y"
+CROSS JOIN "_u_0" AS "_u_0"
+JOIN "x" AS "x"
+ ON "y"."b" = "x"."b"
+GROUP BY
+ "x"."a";