Open info-rchitect opened 3 years ago
Your query is a bit complex, so I tried something else simpler here that demonstrates multiple WITH statements.
from pypika import Table, AliasedQuery, Query
sub_query1 = Query.from_(customers).select('*')
sub_query2 = Query.from_('cust2').select('*')
test_query = (Query
.with_(sub_query, "alias1")
.with_(sub_query2, "alias2")
.from_(AliasedQuery("alias1"))
.select('*')
.from_(AliasedQuery("alias2"))
.select('test'))
print(test_query)
Result is
WITH alias1 AS (SELECT * FROM "customers") ,alias2 AS (SELECT * FROM "cust2") SELECT * FROM alias1,alias2
Hi,
First let me say that I am not a SQL expert so I apologize ahead of time. I went through the unit tests and did not find an example that would reproduce something like this.
I started with this:
The SQL created is:
How can I 'chain' the
AS
statements together within a singleWITH
statement?thx