I have a table,
Output before pivoting:
keli | onoma -----+--------------- name | Step1 a1 | DSP a2 | Tekmiriosi
Expected output:
Step1 | DSP | Tekmiriosi
How to do that for three or more rows but always with to one-row column?
Advertisement
Answer
You can use conditional aggregation:
select max(onoma) filter (where keli = 'name'), max(onoma) filter (where keli = 'a1'), max(onoma) filter (where keli = 'a2') from t;
However, I might suggest that you if you want all values in a single row that you just use arrays:
select array_agg(keli) from t;