直接利用 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;