ahmedrahil786

Day Pass - Paid Vs Promo

Apr 11th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. select
  2. p.reservation_id as rid,
  3. c.comment as couponname,
  4. date(r.occupy_start_at + interval '8' hour) as date,
  5. hour(r.occupy_start_at + interval '8' hour) as startingtime,
  6. timestampdiff(minute,CONVERT_TZ(r.start_at, '+00:00', '+8:00'), CONVERT_TZ(r.end_at, '+00:00', '+8:00'))/60 as ridelength,
  7. date(c.activated_at + interval '8' hour) as activateddate,
  8. date(c.used_at + interval '8' hour) as useddate,
  9. sum(case when p.state = 'normal' and p.paid_type = 'card' then p.amount end) as NetRev,
  10. sum(case when p.state = 'normal' and p.paid_type = 'coupon' then p.amount end) as coupRev
  11.  
  12. from payments p
  13.  
  14. left join reservations r
  15. on p.reservation_id = r.id
  16.  
  17. left join coupons c
  18. on c.reservation_id = p.reservation_id
  19.  
  20. where p.state = 'normal'
  21. and r.start_at + interval '8' hour >= '2019-3-1'
  22. and r.start_at + interval '8' hour < '2019-4-1'
  23. and r.state = 'completed'
  24.  
  25. group by rid
  26.  
  27. order by p.amount desc
Advertisement
Add Comment
Please, Sign In to add comment