Converting rows to columns using crosstab in PostgreSQL not working (relation "table" does not exist)
The CTE is not visible inside the crosstab() function. You have to pass the complete query string including the CTE.

Possible alternative: create a temporary table instead of the CTE.

However, there are more problems in your query. all_correct seems undefined. Etc.

Basic instructions:


PostgreSQL Crosstab Query