我發現的東西,我不能用我自己解決。缺乏解決問題的技巧... :(不同用戶,獲得最後的登錄信息
我需要從這個表例如得到的結果來選擇與他的ID每個用戶,並顯示他們的最後一次登錄信息, :
id name loginTime logoutTime
3 test 2013-11-25 22:50:00 null
4 test1 2013-11-20 07:23:18 null
6 test2 2013-11-19 11:17:22 null
3 test3 2013-11-27 14:20:54 null
16 test4 2013-11-09 13:52:21 null
3 test 2013-12-02 23:07:43 null
2 test5 2013-11-11 18:15:31 null
4 test1 2013-11-17 19:13:59 null
6 test2 2013-11-30 03:10:07 null
...
我需要得到:
id name loginTime logoutTime
2 test5 2013-11-11 18:15:31 null
3 test 2013-12-02 23:07:43 null
4 test1 2013-11-20 07:23:18 null
6 test2 2013-11-30 03:10:07 null
16 test4 2013-11-09 13:52:21 null
...
到目前爲止,我已經使用DISTINCT給不同用戶,但與讓每個不同的用戶登錄的最後日期的問題...
w ^帽子是實現這一目標的最佳方式嗎?
OK,我覺得愚蠢現在...當我看到函數max()和組由我很慚愧......簡單的功能和分組解決了這個問題...對不起,讓你煩惱...... – dovla091