**Table 1**
Tbcode description Amount
2 debtors 40000
3 creditors 50000
4 share_capital 10000
5 reserve 20000
**Table 2**
Tbcode description Amount
1 debtors 3000
2 creditors 7000
3 share_capital 0
4 reserve 3000
4 reserve 2000
2 creditors 300
3 share_capital 3000
4 reserve 3000
1 debtors 2000
我必须在table 1
在我的输出table I
中,table 1
的所有列和amount
列的总和需要TB code
。
我写了以下脚本:
select openingtb.TBCODE,openingtb.DESCRIPTION,openingtb.AMOUNT,count(journals.AMOUNT)
from openingtb
left outer join journals
on openingtb.tbcode = journals.TBCODE
group by journals.TBCODE.TBCODE
;
有人可以指导我哪些代码错误,以及获得所需输出的正确代码是什么
答案 0 :(得分:0)
你使用聚合函数,那么你应该对select子句中使用的所有非聚合字段进行分组......
SELECT openingtb.TBCODE, openingtb.DESCRIPTION, openingtb.AMOUNT
, Count(journals.AMOUNT)
FROM openingtb
LEFT JOIN journals
ON openingtb.tbcode = journals.TBCODE
GROUP BY openingtb.TBCODE, openingtb.DESCRIPTION, openingtb.AMOUNT
;