开发者

Selecting most recent row, per user

I have a table with columns user_id, time_stamp and activity which I use for recoding user actions for an audit trail.

Now, I would just like to get the most recent timestamp for each unique 开发者_Python百科user_id. How do I do that?


SELECT MAX(time_stamp), user_id FROM table GROUP BY user_id;


The following query should be what you want...

select user_id,max(time_stamp) from yourtable group by user_id order by user_id, time_stamp desc 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜