我想要信用,借记和余额的结果总和代码明智,但我担心如何使用所有公司部门的帐户代码组
Select 'All Companies' as DivisionNameEn,
a.LF_CompanyDivisionID,
a.AccountCode as code,
a.AccountNameEn as name,
sum(ISNULL(Credit,0) - ISNULL(Debit,0)) as balance,
sum(ISNULL(Credit,0)) as credit,
sum(ISNULL(debit,0)) as debit
from View_ChartOfAccount a
group by a.AccountCode
它给了我错误
列'View_ChartOfAccount.LF_CompanyDivisionID'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
答案 0 :(得分:0)
你想要那样的东西;
select Code, sum(balance), sum(credit), sum(debit) from
table
where DivisionNameEn = 'All Companies'
group by Code
每sum
次 Code
次计算,并应用All Companies