请各位大虾看看我的代码! (100分)

  • 主题发起人 主题发起人 own_delphi
  • 开始时间 开始时间
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
 
太长了,看的眼花,呵呵
我不知道你试过 union语句没有
select distinct 车间,组别,姓名。。 form cpwg
where...
union
select distinct 车间,组别,姓名。。 form bhdg
where...
union
....
 
接受答案了.
 
后退
顶部