Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://pgexercises.com/questions/aggregates/rankmembers.html
- with t1 as (
- select firstname, surname, ROUND(sum(slots/2.0),-1) as hours
- -- round(x,-1) rounds x to nearest 10, https://stackoverflow.com/a/41210389
- from cd.bookings b
- join cd.members m
- on b.memid = m.memid
- group by 1, 2
- order by 3 desc, 2 asc, 1 asc
- )
- select *, rank() over(order by hours desc)
- from t1
Add Comment
Please, Sign In to add comment