I have a table called user_revenue which looks like this
So the query I need, if ran for the user 'AAA' should only return the last row.
SELECT *
FROM user_revenue
WHERE user_Id = 'AAA' /*Change according to user_id*/
AND revenues > (SELECT revenues FROM (
SELECT revenues, MIN(date) FROM user_revenue
WHERE user_id='AAA' ))/*Change according to user_id*/
I managed to write this which gets the job done, but ideally I'd like to only have to type the user_id one time in the query (whereas here it needs to be typed twice), is there a way to do that?