select isnull(SUM(netPaid),0.00) from dbo.F_AccountEntry a
right join dbo.RPT_resultA41 b
on a.CompanyID=b.CompanyID
and a.AcctID=b.acctid
and b.CompanyID=1 and b.userName='sally_law'
and a.FiscalDateID>-13 and a.FiscalDateID<0
group by b.acctid
如上语句,我的B表在and b.CompanyID=1 and b.userName='sally_law' 条件下 只有66条数据,
但这样出来的如果却有77条之多,什么原因呢,是我的语句有问题吗?
SELECT a.acctid,isnull(bb.closingAmtBase,0) closingAmtBase FROM a LEFT JOIN (
SELECT SUM(closingAmtBase) closingAmtBase ,acctid,companyid FROM b
GROUP BY acctid,companyid
) bb ON bb.companyid = a.companyid AND bb.acctid = a.acctid