like this...declare @ID_Downloads table (ID varchar(30),NumDownloads int,Date datetime)insert into @ID_Downloads select 'AA12345678',20, '01/02/2007' union allselect 'AA12345678',20, '20070302' union allselect 'AB12385845',50, '20070712' union allselect 'BC84757383',66, '20070705' union allselect 'CC91828374',25, '20070808' union allselect 'BC84757383',30, '20070615' union allselect 'EE84725754',45, '20060525'declare @ID_List table (ID varchar(30), Title varchar(30))insert into @ID_List select 'AA12345678','fax' union all select 'AB12385845','picture' union allselect 'BC84757383' ,'calendar' union allselect 'CC91828374','letter' union allselect 'CC98374834','invoice' union all select 'DD89427472','memo'declare @ID_Scores table (ID varchar(30),Score int)insert into @ID_Scores select 'AA12345678',4 union allselect 'AB12385845',0 union allselect 'BC84757383',3 union allselect 'CC91828374',5 union allselect 'CC98374834',0 union allselect 'AA12345678',3select t.id,title,downloads,sum(score) as scoresfrom(select d.id,l.Title,sum(NumDownloads) as Downloadsfrom @ID_Downloads dleft outer join @ID_List l on d.ID = l.IDwhere year(Date) = 2007group by d.ID,Title) tjoin @id_scores s on s.id = t.idgroup by t.id,title,downloads
Em