NonplayerCharacter

PGExercises.com | PostgreSQL | Distinct on

Mar 7th, 2022 (edited)
1,689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- https://pgexercises.com/questions/aggregates/nbooking.html
  2.  
  3. with t1 as(
  4.   select surname, firstname, m.memid, starttime
  5.   from cd.members m
  6.   join cd.bookings b
  7.   on b.memid = m.memid
  8.   where starttime::DATE >= '2012-09-01'
  9.   group by 1,2,3,4 -- removing group by produces wrong data in the next step
  10.   order by 3 asc
  11. )
  12.  
  13. select distinct on (3) *
  14. from t1
  15.  
Add Comment
Please, Sign In to add comment