This is the general structure of my table
USERID | QUANTITY | FRIEND_ID | DATE
---------------------------------------------------
1 | 3 | 7 | 2019-06-22 10:00:00
2 | 2 | 8 | 2019-06-22 11:00:00
1 | 2 | 5 | 2019-06-22 12:00:00
Then I want to group these data like this
SELECT USERID,
SUM(QUANTITY) AS COUNT,
// I NEED THE FRIEND_ID OF THE RECORD WITH MAX(DATE)
MAX(DATE)
FROM THISTABLE
GROUP BY USERID
How can I select the value of a column based on the grouped value of another column?