ahmedrahil786

Row Number without Function = Rahil

Nov 26th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. set @row_number := 0;
  2.  
  3. Select I.* from
  4. (SELECT
  5. @row_number:= CASE
  6. WHEN @customer_no = A.mid
  7. THEN @row_number + 1
  8. ELSE 1
  9. END AS num,
  10. @customer_no:= A.mid mid,
  11. A.rid
  12. FROM
  13. (select distinct r.member_id as mid,
  14. r.id as rid
  15. from reservations r
  16. left join members m on r.member_id = m.id
  17. where r.state in ('completed')
  18. and m.imaginary in ('sofam', 'normal')
  19. and r.member_id not in ('125', '127')
  20. group by rid
  21. order by mid,rid asc) A
  22. ORDER BY mid,rid) I
  23. where I.num < 6
Advertisement
Add Comment
Please, Sign In to add comment