select *
,(select sum(Budget) 
    from b 
   where Position = a.Position
         and a.Name = (select max(name) from a c where Position = a.Position)
  )
from A

解决方案 »

  1.   

    select A.name, A.position, case when A.name = (select top 1 name from A where position = B.position) then B.budget else 0 end from A inner join B on A.position = B.position
      

  2.   

    select *
    ,isnull((select sum(Budget) 
        from b 
       where Position = a.Position
             and a.Name = (select top 1 name 
                             from a c 
                             where Position = a.Position 
                          order by name),0)
      )
    from A
    select *
    ,isnull((select sum(Budget) 
        from b 
       where Position = a.Position
             and a.Name = (select max(name) from a c where Position = a.Position)
      ),0)
    from A