Code:
create table #testdata (DEPNO int, ENAME varchar(20), SAL int)
insert into #testdata select /*
DEPNO ENAME SAL
------ ---------- ---------- */
10,'MILLER' , 1300 union all select
10,'CLARK ' , 2450 union all select
10,'KING ' , 5000 union all select
20,'SMITH ' , 800 union all select
20,'ADAMS ' , 1100 union all select
20,'JONES ' , 2975 union all select
20,'FORD ' , 3000 union all select
20,'SCOTT ' , 3000 union all select
30,'JAMES ' , 950 union all select
30,'MARTIN' , 1250 union all select
30,'WARD ' , 1250 union all select
30,'TURNER' , 1500 union all select
30,'ALLEN ' , 1600 union all select
30,'BLAKE ' , 2850
select a.*, b.DEPSAL
from #testdata a
join (select DEPNO, sum(SAL)DEPSAL from #testdata group by DEPNO) b
on a.DEPNO=b.DEPNO
drop table #testdata
DEPNO ENAME SAL DEPSAL
----------- ----- ----------- -----------
10 MILLER 1300 8750
10 CLARK 2450 8750
10 KING 5000 8750
20 SMITH 800 10875
20 ADAMS 1100 10875
20 JONES 2975 10875
20 FORD 3000 10875
20 SCOTT 3000 10875
30 JAMES 950 9400
30 MARTIN 1250 9400
30 WARD 1250 9400
30 TURNER 1500 9400
30 ALLEN 1600 9400
30 BLAKE 2850 9400