0

I have a table like this:

X,Y,Z,A,B,C
X,Y,Z,D,E,F
X,Y,Z,G,H,I
X,Y,W,A,C,D
X,Y,W,H,I,J

Obviously it is non-normalized table. I want a query that returns the following result:

X,Y,Z,{{A,D,G},{B,E,H},{C,F,I}}
X,Y,W,{{A,H},{C,I},{D,J}}

Normalization is very expensive.Any ideas?

0

1 Answer 1

1

try this:

SELECT c1,c2,c3,ARRAY[array_agg(c4),array_agg(c5)]
from your_table
group by c1,c2,c3
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.