日期:2014-05-16  浏览次数:20787 次

按日期分组统计用户数
如图表:
id username loginip logintime
117 zhangsan 127.0.0.1 2012-10-08 14:42:09
116 testaaa 127.0.0.2 2012-10-08 11:41:30
115 zhangsan 127.0.0.1 2012-10-08 10:32:34
114 wangwu 127.0.0.3 2012-09-29 15:37:34
113 wangwu 127.0.0.3 2012-09-29 15:34:29

如何统计结果为:
日期 用户数 登录次数
date totalUser totalLogin 
2012-10-08 2 3 
2012-09-29 1 2

目前我统计登录次数是用的SQL
SELECT DATE_FORMAT(a.loginTime,'%Y-%c-%d') logindate,COUNT(a.username) FROM g_user_login_log a GROUP BY logindate ORDER BY a.loginTime
用户数好像要group by userid了,这样就涉及到转向,比较麻烦。。有没有比较简洁的统计语句。。

------解决方案--------------------
select DATE_FORMAT(a.loginTime,'%Y-%c-%d') logindate,COUNT(distinct a.username) as totalUser,count(*) as 登录次数
from g_user_login_log a 
GROUP BY logindate 
ORDER BY a.loginTime
------解决方案--------------------
探讨

select DATE_FORMAT(a.loginTime,'%Y-%c-%d') logindate,COUNT(distinct a.username) as totalUser,count(*) as 登录次数
from g_user_login_log a
GROUP BY logindate
ORDER BY a.loginTime