Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- c.coupon_policy_id,
- c.comment,
- count(distinct r.id),
- sum(timestampdiff(hour, r.occupy_start_at, r.occupy_end_at)),
- IFNULL(sum(A.Paid),'') as Paidspend,
- IFNULL(sum(A.Promo),'') as Promospend,
- cp.requester,
- cp.requester_team
- from coupons c
- join reservations r
- on r.id = c.reservation_id
- join coupon_policies cp on cp.id = c.coupon_policy_id
- join (
- select
- p.reservation_id as rid,
- sum(case when p.paid_type = 'card' then. p.amount end) as Paid,
- sum(case when p.paid_type = 'coupon' then p.amount end) as Promo
- from payments p
- group by p.reservation_id) A
- on A.rid = r.id
- where r.start_at + interval '8' hour >= '2019-1-1'
- and r.start_at + interval '8' hour < '2019-12-31'
- and r.state = 'completed'
- group by 1;
Advertisement
Add Comment
Please, Sign In to add comment