今天老板要一个统计的数据:要获取三个月内每天的活跃客户数
表数据:每天会存在多条客户的登录数据,客户的标识字段是contact_qq,时间字段是add_time
sql:
select time, count(*) as count from( select DATE_FORMAT(add_time,'%Y-%m-%d') AS time, count(*) AS count from customer_login_info where add_time>= STR_TO_DATE('2021-09-01 00:00:00','%Y-%m-%d %H:%i:%s') and add_time<= STR_TO_DATE('2021-12-30 23:59:59','%Y-%m-%d %H:%i:%s') group by add_time,contact_qq )temp group by time
GROUP BY X, Y意思是将所有具有相同X字段值和Y字段值的记录放到一个分组里