I have the following table quotations
that serves to fetch the totals of several budgets. And each budget has one piece ( part_id
) that can have several works:
+---------+-------------+----------+-----------------+
| part_id | alternative | revision | totals |
+---------+-------------+----------+-----------------+
| 1 | 1 | 0 | 252.22 |
| 2 | 0 | 0 | 452 |
| 1 | 1 | 1 | 270 |
| 1 | 2 | 2 | 250 |
| 1 | 2 | 3 | 250 |
+---------+-------------+----------------------------+
In the table, I want to sum all the totals, but taking into account the following rules:
- the part_id and alterantive is like a different budget
- If there is more than one revision ( revision
), I'll get the last revision total.
That is, I initially need to stick with the following:
+---------+-------------+----------+-----------------+
| part_id | alternative | revision | totals |
+---------+-------------+----------+-----------------+
| 2 | 0 | 0 | 452 |
| 1 | 1 | 1 | 270 |
| 1 | 2 | 3 | 250 |
+---------+-------------+----------------------------+
That is, in order to get the last revision for each alternative, I want to add the final total, which would be 972.