left join on 多表同表不同条件

cn6177770 cn6177770 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
sql="select a.ID as DID,"
sql=sql&" IsNull(sum(b.Signing_AmountIN),0) as q1a,"
sql=sql&" IsNull(sum(c.Signing_AmountIN),0) as q2a"
sql=sql&" from KL_Depart as a"

sql=sql&" left join KL_Signing b"
sql=sql&" on b.DepartID = a.ID"
sql=sql&" and b.Signing_Stage = 3 and b.UnitID = "&KL_UnitID&" and b.Signing_UseDate between '"&CDate(BDate)&"' and '"&CDate(BDate2)&"'"

sql=sql&" left join KL_Signing c"
sql=sql&" on c.DepartID = a.ID"
sql=sql&" and c.Signing_Stage = 3 and c.UnitID = "&KL_UnitID&" and c.ISCheckD = 1 and c.Signing_UseDate between '"&CDate(BDate)&"' and '"&CDate(BDate2)&"'"


sql=sql&" where a.UnitID ="&KL_UnitID&" and a.ISWriteOFF = 0"
sql=sql&" group by a.ID"
sql=sql&" order by q1a desc"


如果我只Left join 一个的话,结果是正确的,但是我再增加了一个Left Join的话,结果q1a是正确结果的2倍,q2a是正确结果的3倍,请指点一下。
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
cn6177770
ASP 28,401 成员 356,940 内容