日期:2014-05-17 浏览次数:20587 次
use tempdb
go
if OBJECT_ID('Tempdb..#dept') is not null
drop table #dept
create TABLE #dept
(depid int,dename varchar(6))
insert #dept
select 1,'部门一' union all
select 2,'部门二' union all
select 3,'部门三'
if OBJECT_ID('Tempdb..#salary') is not null
drop table #salary
create TABLE #salary
(personid varchar(6),depid int,salary decimal(10,2))
insert #salary
select '100001',1,2000 union all
select '200001',2,3000 union all
select '200002',2,4000
go
select b.dename 部门名称,SUM(a.salary) 薪资总数
from #salary a inner join #dept b on a.depid=b.depid
group by b.dename
having SUM(a.salary)>5000
select a.dename,sum(b.salary) from
dept a,salary b where a.depid=b.depid
group by a.dename
having sum(b.salary)>5000