ahmedrahil786

Duration Length by Hour - Rahil

Aug 7th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. set @startdate1 = '2019-07-01';
  2. set @startdate2 = '2019-08-01';
  3. select distinct r.id,
  4. Date(r.return_at + interval '8' hour) as return_Date ,
  5. hour(r.start_at + interval '8' hour) as Resv_start_hour,
  6. count(distinct case when hour(r.start_at + interval '8' hour) = 0 then r.id end) as 00_00_hr,
  7. count(distinct case when hour(r.start_at + interval '8' hour) = 1 then r.id end) as 00_01_hr,
  8. count(distinct case when hour(r.start_at + interval '8' hour) = 2 then r.id end) as 00_02_hr,
  9. count(distinct case when hour(r.start_at + interval '8' hour) = 3 then r.id end) as 00_03_hr,
  10. count(distinct case when hour(r.start_at + interval '8' hour) = 4 then r.id end) as 00_04_hr,
  11. count(distinct case when hour(r.start_at + interval '8' hour) = 5 then r.id end) as 00_05_hr,
  12. count(distinct case when hour(r.start_at + interval '8' hour) = 6 then r.id end) as 00_06_hr,
  13. count(distinct case when hour(r.start_at + interval '8' hour) = 7 then r.id end) as 00_07_hr,
  14. count(distinct case when hour(r.start_at + interval '8' hour) = 8 then r.id end) as 00_08_hr,
  15. count(distinct case when hour(r.start_at + interval '8' hour) = 9 then r.id end) as 00_09_hr,
  16. count(distinct case when hour(r.start_at + interval '8' hour) = 10 then r.id end) as 00_10_hr,
  17. count(distinct case when hour(r.start_at + interval '8' hour) = 11 then r.id end) as 00_11_hr,
  18. count(distinct case when hour(r.start_at + interval '8' hour) = 12 then r.id end) as 00_12_hr,
  19. count(distinct case when hour(r.start_at + interval '8' hour) = 13 then r.id end) as 00_13_hr,
  20. count(distinct case when hour(r.start_at + interval '8' hour) = 14 then r.id end) as 00_14_hr,
  21. count(distinct case when hour(r.start_at + interval '8' hour) = 15 then r.id end) as 00_15_hr,
  22. count(distinct case when hour(r.start_at + interval '8' hour) = 16 then r.id end) as 00_16_hr,
  23. count(distinct case when hour(r.start_at + interval '8' hour) = 17 then r.id end) as 00_17_hr,
  24. count(distinct case when hour(r.start_at + interval '8' hour) = 18 then r.id end) as 00_18_hr,
  25. count(distinct case when hour(r.start_at + interval '8' hour) = 19 then r.id end) as 00_19_hr,
  26. count(distinct case when hour(r.start_at + interval '8' hour) = 20 then r.id end) as 00_20_hr,
  27. count(distinct case when hour(r.start_at + interval '8' hour) = 21 then r.id end) as 00_21_hr,
  28. count(distinct case when hour(r.start_at + interval '8' hour) = 22 then r.id end) as 00_22_hr,
  29. count(distinct case when hour(r.start_at + interval '8' hour) = 23 then r.id end) as 00_23_hr
  30. from reservations r left join members m on r.member_id = m.id
  31. where r.state in ('completed','inUse')
  32. and r.return_at + interval 8 hour >= @startdate1
  33. and r.return_at + interval 8 hour <= @startdate2
  34. and m.imaginary in ('sofam', 'normal')
  35. and r.member_id not in ('125', '127')
  36. and m.state = 'normal'
  37. group by r.id
Advertisement
Add Comment
Please, Sign In to add comment