ahmedrahil786

Member first 10 reservation dates - Rahil

Feb 13th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. set @row_number := 0;
  2.  
  3.  
  4. Select P.mid as mid, MAX(P.first) as first,
  5. MAX(P.second) as second, MAX(P.third) as third, MAX(P.fourth) as fourth, MAX(P.fifth) as fifth, MAX(P.sixth) as sixth, MAX(P.seventh) as seventh, MAX(P.eight) as eight, MAX(P.nine) as nine, MAX(P.ten) as ten
  6. from
  7. (Select Distinct L.mid,
  8. IF (L.num= 1 , L.date, 0) as first,
  9. IF (L.num= 2 , L.date, 0) as second,
  10. IF (L.num= 3 , L.date, 0) as third,
  11. IF (L.num= 4 , L.date, 0) as fourth,
  12. IF (L.num= 5 , L.date, 0) as fifth,
  13. IF (L.num= 6 , L.date, 0) as sixth,
  14. IF (L.num= 7 , L.date, 0) as seventh,
  15. IF (L.num= 8 , L.date, 0) as eight,
  16. IF (L.num= 9 , L.date, 0) as nine,
  17. IF (L.num= 10 , L.date, 0) as ten
  18. from
  19. (Select I.num as num, I.mid as mid, I.rid as rid, I.date as date from
  20. (SELECT
  21. @row_number:= CASE
  22. WHEN @customer_no = A.mid
  23. THEN @row_number + 1
  24. ELSE 1
  25. END AS num,
  26. @customer_no:= A.mid mid,
  27. A.rid, A.date as date
  28. FROM
  29. (select distinct r.member_id as mid,
  30. r.id as rid,
  31. date(r.start_at + interval 8 hour) as date
  32. from reservations r
  33. left join members m on r.member_id = m.id
  34. where r.state in ('completed')
  35. and m.imaginary in ('sofam', 'normal')
  36. and r.member_id not in ('125', '127')
  37. group by rid
  38. order by mid,rid asc) A
  39. ORDER BY mid,rid) I) L
  40. order by 1 asc) P
  41. #where P.first != 0
  42. group by 1
  43. order by 1 asc
Advertisement
Add Comment
Please, Sign In to add comment