ahmedrahil786

MFTs by Hour - Rahil

Nov 22nd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. set @startDate = "2019-1-01 00:00:00";
  2.  
  3. select
  4. A.date,
  5. count(distinct mid) as TotMFTs,
  6. count(distinct case when dur <= 1 then mid end) AS "<1",
  7. count(distinct case when dur <= 2 then mid end) AS "<2",
  8. count(distinct case when dur <= 3 then mid end) AS "<3",
  9. count(distinct case when dur <= 4 then mid end) AS "<4",
  10. count(distinct case when dur <= 5 then mid end) AS "<5",
  11. count(distinct case when dur > 6 and dur <= 12 then mid end) AS "6-12",
  12. count(distinct case when dur > 12 and dur <= 24 then mid end) AS "12-24",
  13. count(distinct case when dur > 24 and dur <= 48 then mid end) AS "24-48",
  14. count(distinct case when dur > 48 then mid end) AS ">48"
  15. from(
  16. select
  17. r.id as rid,
  18. Date(r.return_at + interval 8 hour) as date,
  19. timestampdiff(minute, r.start_at, r.end_at)/60 as dur,
  20. ifnull((select min(id) from reservations where state in ('completed') and r.member_id=member_id group by member_id),0) as firstRes,
  21. m.id as mid,
  22. str_to_date(m.birthday, '%Y%m%d') as birthdate,
  23. r.way as way
  24. from cars c, reservations r, members m, zones z
  25. where c.id = r.car_id
  26. and m.id = r.member_id
  27. and z.id = r.start_zone_id
  28. and z.id not in (2,3,101)
  29. and m.imaginary in ('normal', 'sofam')
  30. and r.state in ('completed')
  31. and convert_tz(r.created_at, '+00:00', '+8:00') >= @startDate
  32. having rid=firstRes) A
  33. group by 1
  34. order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment