查询最近3天连续登录的用户总数


select SUM(count) from (  select COUNT(登录时间) as countValue,if(COUNT(登录时间)>=3,1,0)  count from (
            SELECT curdate() as mycreatedate
            union all
            SELECT date_sub(curdate(), interval 1 day) as mycreatedate
            union all
            SELECT date_sub(curdate(), interval 2 day) as mycreatedate
            ) as total
            LEFT JOIN (select * from 表名    where user_id in(SELECT
DISTINCT(用户id)
FROM
表名
WHERE
datediff(NOW(), 登录时间) <= 3))  weweicr   on DATE_FORMAT(weweicr.登录时间,'%Y-%m-%d')=total.mycreatedate   GROUP BY weweicr.用户id

  )  a   
 

上一篇:MYSQL 获取最近多少天时间列表


下一篇:MYSQL查询今天、昨天、7天前、30天、本月数据