user_id UserName created_on dateTime
189 essa amuel 2011-08-26 16:31:13.750 2011-11-08 10:13:49.000
189 essa amuel 2011-08-26 16:31:13.750 2011-11-14 16:38:54.000
19 kessa samuel 2011-08-26 16:31:13.750 2011-11-18 12:56:50.000
19 kessa samuel 2011-08-26 16:31:13.750 2011-11-22 14:12:56.000
如何通过userid
上的group by子句获取每个用户的最新登录时间答案 0 :(得分:4)
SELECT user_id, UserName, last_login = MAX([datetime])
FROM dbo.table
GROUP BY user_id, UserName;
另外,您不应该使用datetime
之类的保留字作为列名。
答案 1 :(得分:4)
SELECT USERNAME, MAX([dateTime]) FROM tablename GROUP BY USERNAME
不是吗?