select user_name , team_name , hours , (select sum(hours ) from table where team_name =a.team_name ) as sum_hours from table a
select a.user_name , a.team_name , a.hours ,b.sum_hours from table a left join (select team_name,sum(hours ) sum_hours , max(hours) as hours from table group by team_name ) b on (a.team_name=b.team_name and a.hours=b.hours )
可能我没说明白,第2张表的每个字段都需要显示的!
(select sum(hours ) from table where team_name =a.team_name ) as sum_hours
from table a
select a.user_name , a.team_name , a.hours ,b.sum_hours
from table a
left join (select team_name,sum(hours ) sum_hours , max(hours) as hours from table group by team_name ) b
on (a.team_name=b.team_name and a.hours=b.hours )