NonplayerCharacter

PostgreSQL | PGExercises.com | Rank users by total hours

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