/* 销售单编号不在核销_销售的自动核销里面,且部门号=传入值,客户编号=传入值,*/ select x.fph, x.ccode, x.ddate, x.invoicetype, x.itotalbilling, x.csalespersoname,SUM(isnull(hx.bchxje,0)) as yhxje,hx.bchxje,'正常运作' as tclx from dbo.ww_cw_xsfp as x left join ww_cw_hxd_xsfp as hx on ccode = hx.fpdjh where cclientnum ='3' and deptnum ='010101' and ccode not in (select fpdjh from dbo.ww_cw_hxd_xsfp where bchxje = fpze) group by x.ccode,x.fph,x.ddate, x.invoicetype, x.itotalbilling, x.csalespersoname,yhxje,hx.bchxje,tclx,hx.fpze,x.dcreatetime order by x.dcreatetime --打脸,如下 SELECT * FROM zsk_cwgl_xsfp left join (select fpcode,isnull(sum(ihxje),0) as iyhxje from zsk_cwgl_hxd_mx group by fpcode) as hxhj on zsk_cwgl_xsfp.ccode=hxhj.fpcode where (ikpze <>hxhj.iyhxje or hxhj.iyhxje is null ) and cbmbh='"+rdm.get("cbmbh")+"' and ckhbh='"+rdm.get("ckhbh")+"' and czzbh='"+rdm.get("czzbh")+"'" 总结:当需要再链接一个表时,把主键和需要的字段从表里搜出来作为另一个数据集再链接