ahmedrahil786

One way Zones Duration vs Non One way Zones Duration - Rahil

Aug 19th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. ################ One way Zones PC PD
  2.  
  3. set @startdate1 = '2019-01-01';
  4. set @startdate2 = '2019-09-01';
  5. Select B.date, sum(C.resv) as resv, Sum(B.ncars) as oneway_zone_cars , Sum(C.dur) as duration, Sum(C.ad_sdur) as ad_sdur, Sum(C.Gross_rev) as Gross_rev, sum(Coupon_spent) as Coupon_spent, sum(Net_rev) as Net_rev ,
  6. Round((sum(C.resv)/Sum(B.ncars)),2) as RESV_PC_PD, Round((Sum(C.dur)/Sum(B.ncars)),2) as DUR_PC_PD, Round((sum(Net_rev)/Sum(B.ncars)),2) as NR_PC_PD from
  7. (select distinct r.start_zone_id as zid
  8. from reservations r
  9. where r.way in ('oneway', 'onewayReturn')
  10. and r.start_at + interval 8 hour > '2019-06-01') A
  11. join
  12. (select
  13. distinct czl.zone_id as zid, Date((czl.log_date)) as date, dayname((czl.log_date)) as weekday, count(distinct czl.car_id ) as ncars , z.city as city , z.region as region
  14. from car_zone_logs czl join zones z on z.id = czl.zone_id
  15. where czl.log_date + interval '8' hour >= @startdate1
  16. and czl.car_state = 'normal'
  17. and czl.zone_state = 'normal'
  18. group by 1,2
  19. order by 2 desc) B
  20. on A.zid = B.zid
  21. left join
  22. (Select I.date as date, count(I.rid) as resv, I.zid as zid, sum(I.dur) as dur, sum(I.ad_sdur) as ad_sdur, sum(I.gross_rev) as Gross_rev, sum(I.coupon_spent) as Coupon_spent, Sum(I.net_rev) as Net_rev from
  23. (select A.rid,A.return_date as date, A.zid, A.dur as dur, A.ad_sdur as ad_sdur, IFNULL(E.charges,0) as gross_rev,
  24. IFNULL(F.coupon_Spent,0) as Coupon_Spent,
  25. round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev from
  26. (select
  27. distinct r.id as rid,
  28. r.start_zone_id as zid,
  29. Date(r.return_at + interval '8' hour) as return_Date,
  30. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  31. round(sum(floor(timestampdiff(minute, r.start_at, r.end_at)/60/24)*12+if(mod(timestampdiff(hour, r.start_at, r.end_at),24)>=12,12,mod(timestampdiff(minute, r.start_at, r.end_at)/60,24))),2) as ad_sdur
  32. from reservations r left join members m on r.member_id = m.id
  33. left join zones z on z.id = r.start_zone_id
  34. where r.state in ('completed')
  35. and r.return_at + interval 8 hour >= @startdate1
  36. and r.return_at + interval 8 hour <= @startdate2
  37. and m.imaginary in ('sofam', 'normal')
  38. and r.member_id not in ('125', '127')
  39. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  40. group by rid) A
  41. left join
  42. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  43. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage')
  44. group by rid) E on A.rid = E.rid
  45. left join
  46. (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
  47. where p.state = 'normal' and p.paid_type = 'coupon'
  48. group by p.reservation_id) F on A.rid = F.rid) I
  49. Group by I.date,I.zid) C
  50. on C.date = B.date and C.zid = A.zid
  51. Group by B.date
  52. order by 1 Desc ;
  53.  
  54. ################ Non- One way Zones PC PD
  55.  
  56.  
  57. set @startdate1 = '2019-01-01';
  58. set @startdate2 = '2019-09-01';
  59. Select B.date, sum(C.resv) as resv, Sum(B.ncars) as oneway_zone_cars , Sum(C.dur) as duration, Sum(C.ad_sdur) as ad_sdur, Sum(C.Gross_rev) as Gross_rev, sum(Coupon_spent) as Coupon_spent, sum(Net_rev) as Net_rev,
  60. Round((sum(C.resv)/Sum(B.ncars)),2) as RESV_PC_PD, Round((Sum(C.dur)/Sum(B.ncars)),2) as DUR_PC_PD, Round((sum(Net_rev)/Sum(B.ncars)),2) as NR_PC_PD from
  61. (select P.zid as zid from
  62. (select distinct r.start_zone_id as zid
  63. from reservations r
  64. where r.start_zone_id not in (2,3,101)) P
  65. left join
  66. (select distinct r.start_zone_id as zid
  67. from reservations r
  68. where r.way in ('oneway', 'onewayReturn')
  69. and r.start_at + interval 8 hour > '2019-06-01'
  70. group by 1
  71. order by 1 asc) Q
  72. on P.zid = Q.zid
  73. where Q.zid is null) A
  74. join
  75. (select
  76. distinct czl.zone_id as zid, Date((czl.log_date)) as date, dayname((czl.log_date)) as weekday, count(distinct czl.car_id ) as ncars , z.city as city , z.region as region
  77. from car_zone_logs czl join zones z on z.id = czl.zone_id
  78. where czl.log_date + interval '8' hour >= @startdate1
  79. and czl.car_state = 'normal'
  80. and czl.zone_state = 'normal'
  81. group by 1,2
  82. order by 2 desc) B
  83. on A.zid = B.zid
  84. left join
  85. (Select I.date as date, count(I.rid) as resv, I.zid as zid, sum(I.dur) as dur, sum(I.ad_sdur) as ad_sdur, sum(I.gross_rev) as Gross_rev, sum(I.coupon_spent) as Coupon_spent, Sum(I.net_rev) as Net_rev from
  86. (select A.rid,A.return_date as date, A.zid, A.dur as dur, A.ad_sdur as ad_sdur, IFNULL(E.charges,0) as gross_rev,
  87. IFNULL(F.coupon_Spent,0) as Coupon_Spent,
  88. round((IFNULL(E.charges,0) - IFNULL(F.coupon_Spent,0)),2) as net_rev from
  89. (select
  90. distinct r.id as rid,
  91. r.start_zone_id as zid,
  92. Date(r.return_at + interval '8' hour) as return_Date,
  93. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  94. round(sum(floor(timestampdiff(minute, r.start_at, r.end_at)/60/24)*12+if(mod(timestampdiff(hour, r.start_at, r.end_at),24)>=12,12,mod(timestampdiff(minute, r.start_at, r.end_at)/60,24))),2) as ad_sdur
  95. from reservations r left join members m on r.member_id = m.id
  96. left join zones z on z.id = r.start_zone_id
  97. where r.state in ('completed')
  98. and r.return_at + interval 8 hour >= @startdate1
  99. and r.return_at + interval 8 hour <= @startdate2
  100. and m.imaginary in ('sofam', 'normal')
  101. and r.member_id not in ('125', '127')
  102. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  103. group by rid) A
  104. left join
  105. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  106. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage')
  107. group by rid) E on A.rid = E.rid
  108. left join
  109. (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
  110. where p.state = 'normal' and p.paid_type = 'coupon'
  111. group by p.reservation_id) F on A.rid = F.rid) I
  112. Group by I.date,I.zid) C
  113. on C.date = B.date and C.zid = A.zid
  114. Group by B.date
  115. order by 1 Desc
Advertisement
Add Comment
Please, Sign In to add comment