I've an SQL select that is pretty simple to write in English but I can't achieve to translate it in SQL. Here it is:
I want the ID of the latest event by user.
The table looks like this:
| COLUMN_NAME | DATA_TYPE |
|-------------|-----------|
| ID | NUMBER |
| OCCURED | DATE |
| USER_ID | NUMBER |
And I've try a lot of manipulations using Max()
, some GroupBys:
SELECT l.user_id, MAX(l.OCCURED)
FROM USER_STATS.LOG l
group by l.user_id, l.occured
order by l.OCCURED DESC
but I didn't succeed.
How could I do this?