ahmedrahil786

Number of reservations on same day by each member - Rahil

Jan 9th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. ################ Daily
  2.  
  3.  
  4. set @startdate1 = '2019-07-01';
  5. set @startdate2 = '2020-02-01';
  6. use socar_malaysia;
  7. select
  8. I.date,
  9. count(I.mid) as total_AMs,
  10. sum(I.resv) as reservations,
  11. count(if(I.resv = 1 , I.mid, null)) as 01_resv,
  12. count(if(I.resv = 2 , I.mid, null)) as 02_resv,
  13. count(if(I.resv = 3 , I.mid, null)) as 03_resv,
  14. count(if(I.resv = 4 , I.mid, null)) as 04_resv,
  15. count(if(I.resv = 5 , I.mid, null)) as 05_resv,
  16. count(if(I.resv = 6 , I.mid, null)) as 06_resv,
  17. count(if(I.resv = 7 , I.mid, null)) as 07_resv,
  18. count(if(I.resv = 8 , I.mid, null)) as 08_resv,
  19. count(if(I.resv = 9 , I.mid, null)) as 09_resv,
  20. count(if(I.resv = 10 , I.mid, null)) as 10_resv,
  21. count(if(I.resv = 11 , I.mid, null)) as 11_resv,
  22. count(if(I.resv >= 12 , I.mid, null)) as 12_resv,
  23. count(if(I.resv >= 24 , I.mid, null)) as 24_resv,
  24. count(if(I.resv >= 48, I.mid, null)) as 48_resv
  25. from
  26. (select date(A.return_date) as date, A.mid as mid, count(A.rid2) as resv from
  27. (select
  28. distinct r.id as rid2, r.member_id as mid,YEAR(r.start_at) - YEAR(m.birthday) as age,
  29. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  30. Date(r.return_at + interval '8' hour) as return_Date
  31. from reservations r left join members m on r.member_id = m.id
  32. left join reservation_appendixes ra on ra.reservation_id = r.id
  33. where r.state in ('completed')
  34. and r.return_at + interval 8 hour >= @startdate1
  35. and r.return_at + interval 8 hour <= @startdate2
  36. and m.imaginary in ('sofam', 'normal')
  37. and r.member_id not in ('125', '127')
  38. and ra.performer not in ('admin')
  39. group by rid2) A
  40. group by 1,2) I
  41. group by 1
  42. order by 1 desc;
  43.  
  44. ############# Weekly
  45.  
  46. set @startdate1 = '2019-07-01';
  47. set @startdate2 = '2020-02-01';
  48. use socar_malaysia;
  49. select
  50. I.week,
  51. count(I.mid) as total_AMs,
  52. sum(I.resv) as reservations,
  53. count(if(I.resv = 1 , I.mid, null)) as 01_resv,
  54. count(if(I.resv = 2 , I.mid, null)) as 02_resv,
  55. count(if(I.resv = 3 , I.mid, null)) as 03_resv,
  56. count(if(I.resv = 4 , I.mid, null)) as 04_resv,
  57. count(if(I.resv = 5 , I.mid, null)) as 05_resv,
  58. count(if(I.resv = 6 , I.mid, null)) as 06_resv,
  59. count(if(I.resv = 7 , I.mid, null)) as 07_resv,
  60. count(if(I.resv = 8 , I.mid, null)) as 08_resv,
  61. count(if(I.resv = 9 , I.mid, null)) as 09_resv,
  62. count(if(I.resv = 10 , I.mid, null)) as 10_resv,
  63. count(if(I.resv = 11 , I.mid, null)) as 11_resv,
  64. count(if(I.resv >= 12 , I.mid, null)) as 12_resv,
  65. count(if(I.resv >= 24 , I.mid, null)) as 24_resv,
  66. count(if(I.resv >= 48, I.mid, null)) as 48_resv
  67. from
  68. (select week(A.return_date) as week, A.mid as mid, count(A.rid2) as resv from
  69. (select
  70. distinct r.id as rid2, r.member_id as mid,
  71. round(sum(timestampdiff(minute, r.start_at, r.end_at)/60),2) as dur,
  72. Date(r.return_at + interval '8' hour) as return_Date
  73. from reservations r left join members m on r.member_id = m.id
  74. left join reservation_appendixes ra on ra.reservation_id = r.id
  75. where r.state in ('completed')
  76. and r.return_at + interval 8 hour >= @startdate1
  77. and r.return_at + interval 8 hour <= @startdate2
  78. and m.imaginary in ('sofam', 'normal')
  79. and r.member_id not in ('125', '127')
  80. and ra.performer not in ('admin')
  81. group by rid2) A
  82. group by 1,2) I
  83. group by 1
  84. order by 1 desc;
Advertisement
Add Comment
Please, Sign In to add comment