Gereralise the query for all user_id
Test this:

select sum_duration, 
       app_name, 
       app_id, 
       user_id
from ( select get_data.*,
              if( @user_id = get_data.user_id, 
                  @rownum := @rownum + 1, 
                  @rownum := 1 + least(0, @user_id := get_data.user_id)) row_number
       from ( select sum(duration) sum_duration, 
                     app_name, 
                     app_id, 
                     user_id 
              from timesheet 
              group by app_id ) get_data, 
            ( select @rownum := 1, @user_id := 0 ) init_vars
       order by user_id, sum_duration DESC
     ) subquery
where row_number &lt;= 5