ahmedrahil786

International Customers - Spend Behavior - Chi-E

Nov 7th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. select A.* , IFNULL(sum(E.charges),0) as gross_rev,
  2. IFNULL(F.coupon_Spent,0) as Coupon_Spent,
  3. round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev , ROUND(sum(E.charges)/A.resv,2) as gross_basket_size, ROUND((IFNULL(E.charges,2) - IFNULL(F.coupon_Spent,0))/A.resv,2) as Net_basketsize from
  4. (select distinct r.member_id as mid,m.display_name as name, r.start_zone_id as start_zone_id, z.region as region, ma.country as country,
  5. count(r.id) as resv
  6. from reservations r left join members m on m.id = r.member_id
  7. left join zones z on z.id = r.start_zone_id
  8. left join member_appendixes ma on ma.member_id = r.member_id
  9. where m.imaginary in ('sofam', 'normal')
  10. and m.state = 'normal'
  11. and r.member_id not in ('125', '127')
  12. and z.id not in (2, 3, 101)
  13. and r.state in ('completed')
  14. and ma.country not like 'MYS'
  15. group by 1) A
  16. left join
  17. (select c.member_id as mid, sum(c.amount) as charges from charges c
  18. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage')
  19. group by 1) E on A.mid = E.mid
  20. left join
  21. (select p.member_id as mid, IFNULL(sum(p.amount),0) as coupon_Spent from payments p
  22. where p.state = 'normal' and p.paid_type = 'coupon'
  23. group by 1) F on A.mid = F.mid
  24. group by 1
Advertisement
Add Comment
Please, Sign In to add comment