我试图从两个表中选择SUMed数据。 这是他们的样子。Mysql从两个表中选择两个SUM
表1:
products | revenue|
------------------|
product1 | 10 |
product2 | 20 |
product1 | 20 |
表2:
products | revenue|
------------------|
product1 | 40 |
product2 | 30 |
product2 | 40 |
所以查询应该总结他们是这样的:
products | revenue|
------------------|
product1 | 70 |
product2 | 90 |
我已经试过这和其他一些疑问,但他们不正确。
SELECT Table1.products, Table1.SUM(`revenue`), Table2.SUM(`revenue`)
FROM Table1
JOIN Table2
ON Table1.products = Table2.products
group by Table1.products;
你能帮帮我,在这种情况下什么是正确的查询?谢谢。
谢谢你,你的回答更正确。 – Geobo