sqlserver 一段代码带来的思维小启发

/* 销售单编号不在核销_销售的自动核销里面,且部门号=传入值,客户编号=传入值,*/
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")+"'"
总结:当需要再链接一个表时,把主键和需要的字段从表里搜出来作为另一个数据集再链接

  

 

转载于:https://www.cnblogs.com/ziyanxiaozhu/p/9916422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值