I have 3 columns in a table called \"purchases\":
id amount price
2 2 21
2 5 9
3 8
SELECT
id,
SUM(amount*price) AS total
FROM mytable
GROUP BY id
Data:
| id | amount | price |
|----|--------|-------|
| 2 | 3 | 19 |
| 2 | 3 | 89 |
| 3 | 203 | 1 |
Result:
id total
2 324
3 203
@sombe: I've just tested your query and it works just fine. Are you sure your mysql is up to date?
The second works fine too: