I have a table like this:
---------------------------------------
| id | name | points | date |
---------------------------------------
| 1 | ana | 1 | 2014-12-10 |
| 2 | tom | 3 | 2015-12-09 |
| 3 | jim | 1 | 2013-12-02 |
| 4 | ana | 9 | 2014-12-10 |
| 5 | tom | 3 | 2015-12-09 |
| 6 | jim | 1 | 2016-12-08 |
| 7 | jim | 5 | 2016-12-08 |
| 8 | ana | 2 | 2016-12-08 |
| 9 | ana | 1 | 2016-12-08 |
| 10 | tom | 2 | 2013-12-07 |
-------------------------------------
In this table, I have a group of names. These names may have duplicate entries on the same date with different points. They also have duplicate entries with different dates. The dates are all different, there is no pattern to them.
My goal is to return the following:
name, SUM(points) WHERE MAX(date) for the name group
So basically my current query is:
SELECT name, SUM(points) FROM table GROUP BY name;
However, I need this to only count point entries in the name group from the latest date for that name group, as opposed to summing all the points from all dates.
How can I do this?