ahmedrahil786

MAU Start time - Each Day - Rahil

Jun 10th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. set @startdate1 = '2019-07-01';
  2. set @startdate2 = '2020-09-01';
  3. Select A.return_Date, Count(A.rid) as Total_resv,
  4. Sum(A._1_hr) as 1_hr,Sum(A._2_hr) as 2_hr,Sum(A._3_hr) as 3_hr,
  5. Sum(A._4_hr) as 4_hr,Sum(A._5_hr) as 5_hr,Sum(A._6_hr) as 6_hr,Sum(A._7_hr) as 7_hr, Sum(A._8_hr) as 8_hr,Sum(A._9_hr) as 9_hr,Sum(A._10_hr) as 10_hr,
  6. Sum(A._11_hr) as 11_hr,Sum(A._12_hr) as 12_hr,Sum(A._13_hr) as 13_hr,Sum(A._14_hr) as 14_hr,Sum(A._15_hr) as 15_hr,Sum(A._16_hr) as 16_hr,Sum(A._17_hr) as 17_hr,
  7. Sum(A._18_hr) as 18_hr,Sum(A._19_hr) as 19_hr,Sum(A._20_hr) as 20_hr,Sum(A._21_hr) as 21_hr,Sum(A._22_hr) as 22_hr,Sum(A._23_hr) as 23_hr, Sum(A._24_hr) as 24hr
  8. from
  9. (select distinct r.id as rid,
  10. Date(r.return_at + interval '8' hour) as return_Date ,
  11. hour(r.start_at + interval '8' hour) as Resv_start_hour,
  12. count(distinct case when hour(r.start_at + interval '8' hour) = 0 then r.id end) as _24_hr,
  13. count(distinct case when hour(r.start_at + interval '8' hour) = 1 then r.id end) as _1_hr,
  14. count(distinct case when hour(r.start_at + interval '8' hour) = 2 then r.id end) as _2_hr,
  15. count(distinct case when hour(r.start_at + interval '8' hour) = 3 then r.id end) as _3_hr,
  16. count(distinct case when hour(r.start_at + interval '8' hour) = 4 then r.id end) as _4_hr,
  17. count(distinct case when hour(r.start_at + interval '8' hour) = 5 then r.id end) as _5_hr,
  18. count(distinct case when hour(r.start_at + interval '8' hour) = 6 then r.id end) as _6_hr,
  19. count(distinct case when hour(r.start_at + interval '8' hour) = 7 then r.id end) as _7_hr,
  20. count(distinct case when hour(r.start_at + interval '8' hour) = 8 then r.id end) as _8_hr,
  21. count(distinct case when hour(r.start_at + interval '8' hour) = 9 then r.id end) as _9_hr,
  22. count(distinct case when hour(r.start_at + interval '8' hour) = 10 then r.id end) as _10_hr,
  23. count(distinct case when hour(r.start_at + interval '8' hour) = 11 then r.id end) as _11_hr,
  24. count(distinct case when hour(r.start_at + interval '8' hour) = 12 then r.id end) as _12_hr,
  25. count(distinct case when hour(r.start_at + interval '8' hour) = 13 then r.id end) as _13_hr,
  26. count(distinct case when hour(r.start_at + interval '8' hour) = 14 then r.id end) as _14_hr,
  27. count(distinct case when hour(r.start_at + interval '8' hour) = 15 then r.id end) as _15_hr,
  28. count(distinct case when hour(r.start_at + interval '8' hour) = 16 then r.id end) as _16_hr,
  29. count(distinct case when hour(r.start_at + interval '8' hour) = 17 then r.id end) as _17_hr,
  30. count(distinct case when hour(r.start_at + interval '8' hour) = 18 then r.id end) as _18_hr,
  31. count(distinct case when hour(r.start_at + interval '8' hour) = 19 then r.id end) as _19_hr,
  32. count(distinct case when hour(r.start_at + interval '8' hour) = 20 then r.id end) as _20_hr,
  33. count(distinct case when hour(r.start_at + interval '8' hour) = 21 then r.id end) as _21_hr,
  34. count(distinct case when hour(r.start_at + interval '8' hour) = 22 then r.id end) as _22_hr,
  35. count(distinct case when hour(r.start_at + interval '8' hour) = 23 then r.id end) as _23_hr
  36. from reservations r left join members m on r.member_id = m.id
  37. where r.state in ('completed','inUse')
  38. and r.return_at + interval 8 hour >= @startdate1
  39. and r.return_at + interval 8 hour <= @startdate2
  40. and m.imaginary in ('sofam', 'normal')
  41. and r.member_id not in ('125', '127')
  42. group by r.id) A
  43. group by A.return_date
  44. Order by A.return_date desc;
Add Comment
Please, Sign In to add comment