Aggregating data
Question:
We would like to group our cats by color
Return 3 rows, each row containing a color and a list of cat names
Return: color, names Order by: color DESC Show Table Schema
Cats:
name | varchar |
breed | varchar |
weight | float |
color | varchar |
age | int |
Correct output but can you use 'array_agg'?
Desired output:
color | names |
Tortoiseshell | Felix,Tigger,Millie,Puss |
Brown | Alfie,Misty,Smokey |
Black | Ashes,Molly,Smudge,Oscar,Charlie |
select color, array_agg(name) as names from cats group by color order by color desc