日期:2014-05-17 浏览次数:20615 次
if object_id('[TBA]') is not null drop table [TBA]
go
create table [TBA] (编号 nvarchar(6),班次 int)
insert into [TBA]
select 'R01',5 union all
select 'R01',8 union all
select 'R02',2 union all
select 'R02',4 union all
select 'R03',4 union all
select 'R03',6 union all
select 'R03',4
if object_id('[TBB]') is not null drop table [TBB]
go
create table [TBB] (编号 nvarchar(6),姓名 nvarchar(4))
insert into [TBB]
select 'R01','张三' union all
select 'R02','李四' union all
select 'R03','王五'
select * from [TBA]
select * from [TBB]
SELECT TBB.姓名,A.班次合计
FROM dbo.TBB
INNER JOIN (SELECT 编号,SUM(班次) AS 班次合计 FROM TBA GROUP BY 编号) A ON A.编号 = TBB.编号
WHERE A.班次合计 >10
/*
姓名 班次合计
张三 13
王五 14*/