The CREATE TABLE needs to be before the common table expression
create temp table foo
as
with cte1 as (
...
), cte2 as (
...
), cte3 as (
...
), cte4 as (
...
), cte5 as (
...
)
select *
from cte5;
CLICK HERE to find out more related problems solutions.