Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @row_number := 0;
- Select P.mid as mid, MAX(P.first) as first,
- 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
- from
- (Select Distinct L.mid,
- IF (L.num= 1 , L.date, 0) as first,
- IF (L.num= 2 , L.date, 0) as second,
- IF (L.num= 3 , L.date, 0) as third,
- IF (L.num= 4 , L.date, 0) as fourth,
- IF (L.num= 5 , L.date, 0) as fifth,
- IF (L.num= 6 , L.date, 0) as sixth,
- IF (L.num= 7 , L.date, 0) as seventh,
- IF (L.num= 8 , L.date, 0) as eight,
- IF (L.num= 9 , L.date, 0) as nine,
- IF (L.num= 10 , L.date, 0) as ten
- from
- (Select I.num as num, I.mid as mid, I.rid as rid, I.date as date from
- (SELECT
- @row_number:= CASE
- WHEN @customer_no = A.mid
- THEN @row_number + 1
- ELSE 1
- END AS num,
- @customer_no:= A.mid mid,
- A.rid, A.date as date
- FROM
- (select distinct r.member_id as mid,
- r.id as rid,
- date(r.start_at + interval 8 hour) as date
- from reservations r
- left join members m on r.member_id = m.id
- where r.state in ('completed')
- and m.imaginary in ('sofam', 'normal')
- and r.member_id not in ('125', '127')
- group by rid
- order by mid,rid asc) A
- ORDER BY mid,rid) I) L
- order by 1 asc) P
- #where P.first != 0
- group by 1
- order by 1 asc
Advertisement
Add Comment
Please, Sign In to add comment