Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @row_number := 0;
- Select I.* 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
- FROM
- (select distinct r.member_id as mid,
- r.id as rid
- 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
- where I.num < 6
Advertisement
Add Comment
Please, Sign In to add comment