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
from sqlglot.optimizer import optimize
print(optimize(q, SCHEMA_DICT).sql(pretty=True))
The output is:
WITH "_u_0" AS (
SELECT
"lineitem"."l_orderkey" AS "l_orderkey"
FROM "lineitem" AS "lineitem"
GROUP BY
"lineitem"."l_orderkey",
"lineitem"."l_orderkey"
HAVING
SUM("lineitem"."l_quantity") > 10
)
SELECT
"customer"."c_custkey" AS "c_custkey",
"orders"."o_orderkey" AS "o_orderkey",
"orders"."o_orderdate" AS "o_orderdate",
"orders"."o_totalprice" AS "o_totalprice",
SUM("lineitem"."l_quantity") AS "_col_4"
FROM "customer" AS "customer"
JOIN "orders" AS "orders"
ON "customer"."c_custkey" = "orders"."o_custkey"
LEFT JOIN "_u_0" AS "_u_0"
ON "_u_0"."l_orderkey" = "orders"."o_orderkey"
JOIN "lineitem" AS "lineitem"
ON "lineitem"."l_orderkey" = "orders"."o_orderkey"
WHERE
NOT "_u_0"."l_orderkey" IS NULL
GROUP BY
"customer"."c_name",
"customer"."c_custkey",
"orders"."o_orderkey",
"orders"."o_orderdate",
"orders"."o_totalprice"
ORDER BY
"o_totalprice" DESC,
"o_orderdate"
and honestly I don't understand why, within the WITH "_u_0" there is a double group by that groups by the "lineitem"."l_orderkey".
Thanks!
The text was updated successfully, but these errors were encountered:
Use the following schema (from tpch):
The output is:
and honestly I don't understand why, within the WITH "_u_0" there is a double group by that groups by the "lineitem"."l_orderkey".
Thanks!
The text was updated successfully, but these errors were encountered: