程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

MYSQL查询当前7天内不重复的登录数

 

直接利用 distinct

SELECT
    DATE_FORMAT( create_time, '%Y-%m-%d' ) AS days,
    count( * ) count,
       count(distinct user_id)
    

FROM
    b_user_login_log 
WHERE
    DATE_SUB( CURDATE( ), INTERVAL 7 DAY ) <= create_time 
GROUP BY
    days;

 

查询当前设备id

SELECT
    DATE_FORMAT( create_time, '%Y-%m-%d' ) AS days,
    count( * ) count,
    GROUP_CONCAT( user_id ) AS userIds 
FROM
    b_user_login_log 
WHERE
    DATE_SUB( CURDATE( ), INTERVAL 7 DAY ) <= create_time 
GROUP BY
    days;

 

赞(0)
未经允许不得转载:程序员一代码搬运工 » MYSQL查询当前7天内不重复的登录数
分享到: 更多 (0)