0

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
sticky bit
  • 36,626
  • 12
  • 31
  • 42
Hyder W
  • 55
  • 1
  • 9
  • *my query is not working* ... what is the error or undesired results? – Parfait Apr 04 '19 at 18:11
  • Possible duplicate of [Quotation mark incorrect when using crosstab() in PostgreSQL](https://stackoverflow.com/questions/9170038/quotation-mark-incorrect-when-using-crosstab-in-postgresql) – Parfait Apr 04 '19 at 18:16

0 Answers0