我有两张 table
表 1
id product
1 P1
2 P2
表2
id amount product_t1
1 100 P1
2 200 P1
3 300 P2
4 400 P1
5 500 P2
我希望我的输出是:
product totalAmount(sum of amount)
P1 700
P2 800
编辑:这是我到目前为止的查询
SELECT T1.product, SUM(T2.amount)
FROM table1 T1
INNER JOIN table2 T2
ON T1.product = T2.product_t1
谢谢!
最佳答案
你应该使用分组方式
SELECT T1.product, SUM(T2.amount)
FROM table1 T1
INNER JOIN table2 T2
ON T1.product = T2.product_t1
GROUP BY product
关于mySQL - 列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42691743/