我一直在尝试使用内部联接进行SUM,但它会显示每个单元格,而不是将它们一起添加并仅显示在一个单元格中,我哪里出错?
SELECT SUM(trans) as 'Transactions',city as 'city'
FROM account
INNER JOIN branch
ON branch.bID
GROUP BY account.trans, branch.city;
答案 0 :(得分:1)
删除account.trans
中的Group by
。由于您在account.trans, branch.city
中添加了group by
,因此每sum(trans)
和trans
会显示city
。
如果您希望每sum(trans)
city
,请在branch.city
group by
SELECT SUM(trans) as 'Transactions'
FROM account
INNER JOIN branch
ON branch.bID
Group by branch.city;
答案 1 :(得分:1)
使用以下查询将返回每个城市的总和
SELECT SUM(trans) as 'Transactions', branch.city as 'city'
FROM account
INNER JOIN branch
ON branch.bID = account.bID
GROUP BY branch.city;