0
我這樣的twp表。與總和合並的MySql表
+----+--------+ +----------+-------+--------+
| id | fruit | | fruit_id | color | amount |
+----+--------+ +----------+-------+--------+
結果爲:
SELECT
fruit,amount
FROM
table1,table2
WHERE fruit_id = id
+--------+--------+
| fruit | amount |
+--------+--------+
| Apple | 5 |
| Apple | 5 |
| Cherry | 2 |
| Cherry | 2 |
+--------+--------+
但我想這樣的結果:
+--------+--------+
| fruit | amount |
+--------+--------+
| Apple | 10 |
| Cherry | 4 |
+--------+--------+
我該怎麼辦,懇求幫助我..
Thenks ...
+1擊敗了我。 – Kermit
This OK「SELECT fruit,sum(amount)Total FROM table1 inner join table2 on fruit_id = id group by fruit」Thenks ... –
@MahmutEsinti是的,這是正確的,應該返回結果。 – Taryn