我在MySql中有两个表。 表1:MySql LEFT JOIN只从另一个表中返回一个NULL行
id account_no
1 123
2 124
3 125
4 126
5 127
表2:
id amount
1 200
1 300
2 400
3 300
2 100
我所需的输出是:
account_no total_amount
123 500
124 500
125 300
126 0
127 0
我的查询如下
SELECT a.account_no AS 'account_no', IFNULL(SUM(b.amount),0) AS 'total_amount'
FROM table1 a
LEFT JOIN table2 b
ON a.id = b.id
GROUP BY b.id ORDER BY a.account_no
但与此查询我越来越多y this
account_no total_amount
123 500
124 500
125 300
126 0
任何人都可以帮助我吗?
谢谢。这有助于:) – rin2