本帖最后由 m582445672 于 2015-01-26 15:54:01 编辑

解决方案 »

  1.   

    为什么有几行的结果是null这是需求? 如果不是select  team_name ,sum(hours) sum_hours from  table group by  team_name 其他几个字段展示是没有意义的
      

  2.   

    你这样,没有显示user_name和hours哦!~
    可能我没说明白,第2张表的每个字段都需要显示的!
      

  3.   

    select user_name   ,   team_name   ,    hours ,
    (select sum(hours ) from table where  team_name       =a.team_name       ) as sum_hours   
    from table a
      

  4.   


    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 )