CTE executed multiple times
Please see the docs for cte usage. I get the sense you're missing something:

http://docs.peewee-orm.com/en/latest/peewee/querying.html#common-table-expressions

The tests also have numerous examples. My misunderstanding was based on the assumption that `.with_cte(...)` should have been added to each [sub]query which refers to the CTE, while it just adds a `WITH ... AS` at the beginning of the [sub]query.

My problem has been fixed by using `.with_cte(...)` just once, at the very end of the main query.
Hi,
Peewee defines CTE in subqueries, even if that means to compute the same thing twice.

For example: `SELECT ... FROM ... JOIN (WITH cte ... SELECT ... FROM cte) JOIN (WITH cte ... SELECT ... FROM cte) ...`

I have a rather complex example I can show, but it surprises me that the CTE is not placed at the beginning, as that has been defined once.