I am looking to pivot my query in Postgres using the crosstab function. I've created the extension: tablefunc but my query is not working (i've executed the inner query and it works)
- This is in Pgadmin4
- I've created the tablefunc extension using "Create extension tablefunc"
Below is my query:
select *
from crosstab
(
'select form_type, title, count(title) as total
from table_name
where timestamp >= '2019-01-01'
and title in ('this_form','that_form')
group by form_type, title
order by 1,2,3'
)
AS ct("Form_type" text, "Form" int, "Form_2" int)
Results from inner query:
form_type || title || total
A Form1 5
B Form2 9
WHAT I WANT RETURNED USING CROSSTAB:
form_type || Form1 || Form2
A 5
B 9