ahmedrahil786

Monthly - Number of members with 0 Spent - Rahil

Dec 2nd, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. set @startdate1 = '2019-03-01';
  2. set @startdate2 = '2019-12-30';
  3. use socar_malaysia;
  4. Select Month(I.return_date) as month, Count(Distinct I.mid) as Unique_Free_Riders_Per_month, Count(I.rid) as Unique_Free_reservations_per_month, I.net_rev_WO_Insurance as net_rev_WO_Insurance from
  5. (select A.return_date as return_date, A.rid2 as rid,A.mid as mid, IFNULL(E.charges,0) as gross_rev,
  6. IFNULL(F.coupon_Spent,0) as Coupon_Spent,
  7. round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev,round((IFNULL(E.charges,0) - IFNULL(G.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev_WO_Insurance from
  8. (select
  9. distinct r.id as rid2, r.member_id as mid,
  10. Date(r.return_at + interval '8' hour) as return_Date
  11. from reservations r left join members m on r.member_id = m.id
  12. where r.state in ('completed')
  13. and r.return_at + interval 8 hour >= @startdate1
  14. and r.return_at + interval 8 hour <= @startdate2
  15. and m.imaginary in ('sofam', 'normal')
  16. and r.member_id not in ('125', '127')
  17. group by rid2) A
  18. left join
  19. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  20. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage','insurance')
  21. group by rid) E on A.rid2 = E.rid
  22. left join
  23. (select p.reservation_id as rid, month(p.created_at + interval '8' hour) as month,Year(p.created_at + interval '8' hour) as year, IFNULL(p.amount,0) as coupon_Spent from payments p
  24. where p.state = 'normal' and p.paid_type = 'coupon'
  25. group by p.reservation_id) F on A.rid2 = F.rid
  26. left join
  27. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  28. where c.state='normal' and c.kind in ('insurance')
  29. group by rid) G on A.rid2 = G.rid) I
  30. Where I.net_rev_WO_Insurance = 0
  31. group by 1
Advertisement
Add Comment
Please, Sign In to add comment