I want to SUM the total amount of KG of each unique last value in a table.
The table i currently have looks like this
|----|-----------|----------|----------|----------|---------------|
| id | productId | amountKg | amountSt | location | datetimeStamp |
|----|-----------|----------|----------|----------|---------------|
| 12 | 19 | 201 | 0 | loc1 | 2019-12-21 |
| 13 | 19 | 35 | 0 | loc2 | 2019-12-22 | <---
| 14 | 19 | 400 | 0 | loc1 | 2019-12-23 | <---
|----|-----------|----------|----------|----------|---------------|
And I have this SQL query
SELECT SUM(amountKg) FROM (SELECT amountKg FROM storage GROUP BY location ORDER BY id ASC) t;
Whe I run this query I get the result 236 The result I want is 435, the sum of the 14 and 13 (The arrows in the table)
Any help is appreciated