vgrabovets
12/1/2016 - 9:44 AM

row number over

row number over

SELECT
     date
     , geo
     , @row:=case when @user = user_id then @row + 1 else 1 end as row_num
     , @user:=user_id as user_id
     FROM
     billing.orders o, (select @row:=0, @user:=0) v
     WHERE #service_id = 15601

 type IN
(
  SELECT
    type
  FROM
    daily.dict_pay_system m
  WHERE m.group IN ('M')
)
     AND o.closed = 1

order by user_id, date asc