SQL Server 中的日志表
timestamp user_name session_id
2012-10-17 06:30:10 Sanjay 034A955F
2012-10-17 06:30:20 Sanjay 034A955F
2012-08-20 13:20:59 John 0547961A
2012-08-20 13:21:05 John 0547961A
2012-08-20 13:22:10 John 0547961A
2012-10-17 04:02:10 John 0977661B
期望的输出
user Total_login This_Month_Login Recent_Login
Sanjay 2 2 2012-10-17 06:30:10
John 4 1 2012-10-17 04:02:10
我试图编写 SQL SELECT 查询来获得以上输出,但我不擅长 SQL,所以不能提前写,只写了 2 列。你能帮我得到上面的选择输出吗?
select user_name as 'User', count (distinct session_id) as 'Total_Login'
from "LogTable"
group by user_name