我想要做的是获取最后 4 个 person_id 并将它们相加。这是我当前的 MySQL 查询。我最终得到的是 person_id 23 = 4。当我将 LIMIT 更改为 7 时,我最终得到 person_id 23 = 6,而 person_id 24 = 2。我需要的是
person_id 23 = 4
person_id 24 = 8
person_id 25 = 12
我究竟做错了什么?
SELECT SUM(ms.value) AS value, ms.person_id
FROM
(SELECT mst.value, mst.id, mst.person_id
FROM match_statistic AS mst
WHERE mst.person_id IN (23,24,25)
ORDER BY mst.id ASC
LIMIT 4) AS sub
INNER JOIN match_statistic AS ms ON sub.id = ms.id
GROUP BY ms.person_id
match_statistic table
| id | person_id | value |
| 10 | 23 | 1 |
| 11 | 23 | 1 |
| 12 | 23 | 1 |
| 13 | 23 | 1 |
| 14 | 23 | 1 |
| 15 | 23 | 1 |
| 16 | 24 | 2 |
| 17 | 24 | 2 |
| 18 | 24 | 2 |
| 19 | 24 | 2 |
| 20 | 24 | 2 |
| 21 | 24 | 2 |
| 22 | 25 | 3 |
| 23 | 25 | 3 |
| 24 | 25 | 3 |
| 25 | 25 | 3 |
| 26 | 25 | 3 |
| 27 | 25 | 3 |