0

I need to convert following rows:

table {name,col} values{(x,value1), (x , value2) (x , value3) (x , value2) (x , value3) (y , value1) (y , value3) (y , value3) (z , value1)}

into following columns: {name ,value1, value2 , value3} values{(x,1,2, 2), (y, 1, 0 , 2)(z, 1, 0 , 0)} I use the following code but it doesn't know crosstab:

SELECT * FROM crosstab ( 'SELECT name , col, count(col) FROM table GROUP BY name order by name ) AS (name text, value1 integer, value2 integer, value3 integer)

Ms workaholic
  • 373
  • 2
  • 8
  • 21
  • 1
    Possible duplicate of [PostgreSQL Crosstab Query](https://stackoverflow.com/questions/3002499/postgresql-crosstab-query) – Nick Jun 23 '17 at 22:40

1 Answers1

1

This line should be added before the code: CREATE EXTENSION IF NOT EXISTS tablefunc;

Ms workaholic
  • 373
  • 2
  • 8
  • 21