O
own_delphi
Unregistered / Unconfirmed
GUEST, unregistred user!
[red]下面的源码主要意图是用批处理查询出只有在表cpwg中有的记录[/red],
包括有车间,组别,姓名,缺陷频次等,而在表bhgd,cpfz中如果有相同的记录则不用查询出来,
现在的问题是代码查询出来的是连相同的记录都查询出来了.
[black][/black]
select Rtrim(cj) as 车间,Rtrim(zb) as 组别,
Rtrim(justname) as 姓名,sum(pc) as sumpc,
Rtrim(cj)+Rtrim(zb)+Rtrim(justname) as czx into #a
from bhgd b where cast(year(b.dt) as int)='2002'
and cast(month(b.dt) as int)='11'
and left(b.cj,1)='1'
group by b.cj,b.zb,b.justname
GO
select Rtrim(cj) as 车间,Rtrim(zb) as 组别,
Rtrim(wghj) as 姓名,sum(wgpc) as wgpc,
Rtrim(cj)+Rtrim(zb)+Rtrim(wghj) as czx into #b
from cpwg w where cast(year(w.dt) as int)='2002'
and cast(month(w.dt) as int)='11'
and left(w.cj,1)='1'
group by w.cj,w.zb,w.wghj
GO
select Rtrim(cj) as 车间,Rtrim(zb) as 组别,
Rtrim(fzhj) as 姓名,sum(fzpc) as fzpc,
Rtrim(cj)+Rtrim(zb)+Rtrim(fzhj) as czx into #c
from cpfz f where cast(year(f.dt) as int)='2002'
and cast(month(f.dt) as int)='11'
and left(f.cj,1)='1'
group by f.cj,f.zb,f.fzhj
GO
select distinct #b.车间, #b.组别,#b.姓名,wgpc from #a,#b,#c where
#a.czx<>#b.czx and #a.czx<>#c.czx
go
DROP TABLE #a
DROP TABLE #b
DROP TABLE #c