Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://pgexercises.com/questions/aggregates/payback.html
- -----------------------------
- '''
- We spent initialoutlay per facility
- Every month we spend monthlymaintenance per facility
- Every month we receive revenue per facility
- Difference between revenue and monthly maintenance is what counts against initialoutlay per facility
- '''
- -----------------------------
- with t1 as (select
- name,
- initialoutlay,
- monthlymaintenance,
- sum(slots * (case when memid=0 then guestcost else membercost end))/3 as monthlyrevenue
- from cd.facilities f
- join cd.bookings b
- on f.facid = b.facid
- group by 1, 2, 3)
- select name,
- initialoutlay/(monthlyrevenue-monthlymaintenance) as months
- from t1
- order by 1 asc
Add Comment
Please, Sign In to add comment