ahmedrahil786

Test Queries for Candidates - Rahil

Dec 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. set @startdate1 = '2019-02-01';
  2. set @startdate2 = '2019-03-01';
  3. use socar_malaysia;
  4. select A.rid2 as rid, A.mid as mid, IFNULL(E.charges,0) as gross_rev from
  5. (select
  6. distinct r.id as rid2, r.member_id as mid, z.region, z.city, cc.car_name,IFNULL(co.comment,"") as coupon,
  7. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  8. 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,
  9. IFNULL(sum(ra.mileage),0) as distance,
  10. Date(r.return_at + interval '8' hour) as return_Date,
  11. hour(r.created_at + interval '8' hour) as created_hour,
  12. Date(r.start_at + interval '8' hour) as start_Date,
  13. hour(r.start_at + interval '8' hour) as resv_hour,
  14. hour(r.occupy_start_at + interval '8' hour) as occupy_start_hour,
  15. (YEAR(r.start_at) - YEAR(m.birthday)) as age
  16. from reservations r left join members m on r.member_id = m.id
  17. left join zones z on z.id = r.start_zone_id
  18. left join cars cr on cr.id = r.car_id
  19. left join car_classes cc on cc.id = cr.car_class_id
  20. left join coupons co on co.reservation_id = r.id
  21. left join reservation_appendixes ra on ra.reservation_id = r.id
  22. where r.state in ('completed')
  23. and r.return_at + interval 8 hour >= @startdate1
  24. and r.return_at + interval 8 hour <= @startdate2
  25. and m.imaginary in ('sofam', 'normal')
  26. and r.member_id not in ('125', '127')
  27. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  28. group by rid2) A
  29. left join
  30. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  31. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage','insurance')
  32. group by rid) E on A.rid2 = E.rid
  33. left join
  34. (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
  35. where p.state = 'normal' and p.paid_type = 'coupon'
  36. group by p.reservation_id) F on A.rid2 = F.rid
  37. order by 1 asc;
  38.  
  39.  
  40. set @startdate1 = '2019-02-01';
  41. set @startdate2 = '2019-03-01';
  42. use socar_malaysia;
  43. select A.rid2 as rid, A.mid as mid, IFNULL(F.coupon_Spent,0) as Coupon_Spent
  44. from
  45. (select
  46. distinct r.id as rid2, r.member_id as mid, z.region, z.city, cc.car_name,IFNULL(co.comment,"") as coupon,
  47. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  48. 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,
  49. IFNULL(sum(ra.mileage),0) as distance,
  50. Date(r.return_at + interval '8' hour) as return_Date,
  51. hour(r.created_at + interval '8' hour) as created_hour,
  52. Date(r.start_at + interval '8' hour) as start_Date,
  53. hour(r.start_at + interval '8' hour) as resv_hour,
  54. hour(r.occupy_start_at + interval '8' hour) as occupy_start_hour,
  55. (YEAR(r.start_at) - YEAR(m.birthday)) as age
  56. from reservations r left join members m on r.member_id = m.id
  57. left join zones z on z.id = r.start_zone_id
  58. left join cars cr on cr.id = r.car_id
  59. left join car_classes cc on cc.id = cr.car_class_id
  60. left join coupons co on co.reservation_id = r.id
  61. left join reservation_appendixes ra on ra.reservation_id = r.id
  62. where r.state in ('completed')
  63. and r.return_at + interval 8 hour >= @startdate1
  64. and r.return_at + interval 8 hour <= @startdate2
  65. and m.imaginary in ('sofam', 'normal')
  66. and r.member_id not in ('125', '127')
  67. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  68. group by rid2) A
  69. left join
  70. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  71. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage','insurance')
  72. group by rid) E on A.rid2 = E.rid
  73. left join
  74. (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
  75. where p.state = 'normal' and p.paid_type = 'coupon'
  76. group by p.reservation_id) F on A.rid2 = F.rid
  77. where IFNULL(F.coupon_Spent,0) > 0
  78. order by 1 desc;
  79.  
  80.  
  81. set @startdate1 = '2019-02-01';
  82. set @startdate2 = '2019-03-01';
  83. use socar_malaysia;
  84. select A.return_date as return_date, A.resv_hour as resv_Start_hour, A.rid2 as rid, A.mid as mid, A.region as region, A.city as city, A.car_name as car_name,
  85. A.coupon as coupon, A.dur as dur, A.distance as distance, A.age as age from
  86. (select
  87. distinct r.id as rid2, r.member_id as mid, z.region, z.city, cc.car_name,IFNULL(co.comment,"") as coupon,
  88. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  89. 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,
  90. IFNULL(sum(ra.mileage),0) as distance,
  91. Date(r.return_at + interval '8' hour) as return_Date,
  92. hour(r.created_at + interval '8' hour) as created_hour,
  93. Date(r.start_at + interval '8' hour) as start_Date,
  94. hour(r.start_at + interval '8' hour) as resv_hour,
  95. hour(r.occupy_start_at + interval '8' hour) as occupy_start_hour,
  96. (YEAR(r.start_at) - YEAR(m.birthday)) as age
  97. from reservations r left join members m on r.member_id = m.id
  98. left join zones z on z.id = r.start_zone_id
  99. left join cars cr on cr.id = r.car_id
  100. left join car_classes cc on cc.id = cr.car_class_id
  101. left join coupons co on co.reservation_id = r.id
  102. left join reservation_appendixes ra on ra.reservation_id = r.id
  103. where r.state in ('completed')
  104. and r.return_at + interval 8 hour >= @startdate1
  105. and r.return_at + interval 8 hour <= @startdate2
  106. and m.imaginary in ('sofam', 'normal')
  107. and r.member_id not in ('125', '127')
  108. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  109. group by rid2) A
  110. left join
  111. (select c.reservation_id as rid, sum(c.amount) as charges from charges c
  112. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage','insurance')
  113. group by rid) E on A.rid2 = E.rid
  114. left join
  115. (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
  116. where p.state = 'normal' and p.paid_type = 'coupon'
  117. group by p.reservation_id) F on A.rid2 = F.rid
  118. order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment