More Grouping
Question:
The cats want to show their weight by breed. The cats agree that they should show the second lightest cat's weight (so as not to make other cats feel bad)
Print a list of breeds, and the second lightest weight of that breed
Return: breed, imagined_weight
Order by: breed Show Table Schema
Cats:
name | varchar |
breed | varchar |
weight | float |
color | varchar |
age | int |
Correct output but can you use 'nth_value'?
Desired output:
breed | imagined_weight |
British Shorthair | 4.8 |
Maine Coon | 5.4 |
Persian | 4.5 |
Siamese | 6.1 |
select distinct(breed), nth_value(weight, 2) over ( partition by breed order by weight RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) as imagined_weight from cats order by breed;