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)

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.