NonplayerCharacter

PGexercises.com | 3-table join

Feb 27th, 2023
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PostgreSQL 0.52 KB | Software | 0 0
  1. -- https://pgexercises.com/questions/joins/threejoin2.html
  2. -- They use one long query, but 'with' is cleaner
  3.  
  4. with t1 as(
  5.   select m.firstname || ' ' || m.surname as member,
  6.        f.name as facility,
  7.        b.slots * (case when b.memid = 0 then f.guestcost else f.membercost end) as cost
  8.        from cd.members m
  9.        join cd.bookings b
  10.        on m.memid = b.memid
  11.        join cd.facilities f
  12.        on f.facid = b.facid
  13.        where starttime::DATE = '2012-09-14'
  14.   )
  15.  
  16. select * from t1
  17. where cost > 30
  18. order by 3 desc
Tags: sql
Add Comment
Please, Sign In to add comment