我有一个名为登录的表。我想获取每个用户上次登录的天数
请参阅下面的示例数据:
tableName: Login
ID|UserName|LoginDateTime
1 |User1 |04/09/12 18:07:06
2 |User1 |04/09/12 18:07:51
3 |User1 |04/09/12 18:21:41
4 |Admin |17/09/12 15:36:30
5 |Admin |17/09/12 15:36:30
这是我的 SQL 命令:
SELECT LoginDateTime, UserName,(DATEDIFF (DAY, [LoginDateTime], GETDATE ()))
AS [datediff]
FROM Login;
结果:
ID|UserName|LoginDateTime |No. of Days
1 |User1 |04/09/12 18:07:06|414
2 |User1 |04/09/12 18:07:51|414
3 |User1 |04/09/12 18:21:41|414
4 |Admin |17/09/12 15:36:30|401
5 |Admin |17/09/12 15:36:30|401
但我想删除重复的记录
ID|UserName|LoginDateTime |No. of Days
1 |User1 |04/09/12 18:07:06|414
2 |Admin |17/09/12 15:36:30|401
感谢任何帮助。