Percentiles
Question:
Each cat would like to know what weight percentile it is in. This requires casting to an integer
Return: name, weight, percent
Order by: weight
Show Table
Cats:
| name | varchar |
| breed | varchar |
| weight | float |
| color | varchar |
| age | int |
Show Desired Output
Desired output:
| name | weight | percent |
| Tigger | 3.80 | 8 |
| Molly | 4.20 | 17 |
| Ashes | 4.50 | 25 |
| Charlie | 4.80 | 33 |
| Smudge | 4.90 | 42 |
| Felix | 5.00 | 50 |
| Puss | 5.10 | 58 |
| Millie | 5.40 | 67 |
| Alfie | 5.50 | 75 |
| Misty | 5.70 | 83 |
| Oscar | 6.10 | 100 |
| Smokey | 6.10 | 100 |
Query Window:
Correct output but can you use 'cume_dist'?
×
Good work!
cume_dist() is similar to percent_rank(). The difference is the first entry in cume_dist is not 0. next question
Show Answer
Answer:
select name, weight,
cast(cume_dist() over (order by weight) * 100 as integer) as percent
from cats order by weight