select user_id, avg(time_out - time_in) as avgtime
from work_time
group by user_id
having avgtime > 600
select id, name, usertime.avgtime from user
inner join (
select user_id, avg(time_out - time_in) as avgtime
from work_time
group by user_id
having avgtime > 600
) usertime on user.id = usertime.user_id