for SQL 2005 / 2008 declare @tableA table( People varchar(5), Location char(2), WorkingHours int)insert into @tableAselect 'Sam', 'A1', 5 union allselect 'Sam', 'A2', 10 union allselect 'Peter', 'A1', 5 union allselect 'Peter', 'A2', 1 union allselect 'Cris', 'A3', 20select People, Location, tot_WorkingHoursfrom( select *, row_no = row_number() over (partition by People order by WorkingHours desc), tot_WorkingHours = sum(WorkingHours) over (partition by People) from @tableA) awhere a.row_no = 1
KH[spoiler]Time is always against us[/spoiler]