So I have a table more less like this name it tests_summary:
test_id | completed | remaining | score_date |
---|---|---|---|
200 | 6 | 1 | 2022-05-02 |
200 | 2 | 7 | 2022-05-01 |
200 | 5 | 10 | 2022-04-29 |
200 | 5 | 15 | 2022-04-28 |
199 | 10 | 0 | 2022-05-02 |
199 | 2 | 10 | 2022-05-01 |
First I tried to group by each test_id, SUM every completed by each test, but I want to get in the remaining column, the remaining value in the most recent score date.
Example test_id 200, the most recent date is 2022-05-02, and 1 is remaining that is the value I want. In this table is already ordered but in my real table is not.
Expected result
test_id | completed | remaining |
---|---|---|
200 | 18 | 1 |
199 | 12 | 0 |
version 5.7.12