Hi I have table like this
name | cat_type |
---|---|
coco | Dom |
coky | Anggora |
chee | Turk |
eena | Persian |
onaa | Dom |
haina | Turk |
haani | Dom |
I want to try to transform to this
Dom | Anggora | Turk | Persian |
---|---|---|---|
coco | coky | chee | eena |
onaa | null | haina | null |
haani | null | null | null |
I have tried the following approach:
SELECT *
FROM my_table
PIVOT( STRING_AGG(name) FOR cat_type IN ('Dom','Anggora','Turk','Persian'))
But I didn't get what I want, as I got result like the following:
Dom | Anggora | Turk | Persian |
---|---|---|---|
coco,onaa,haani | coky | chee,haina | eena |
Is there something wrong in my query?
Thank you in advance!