WITH t1 AS( SELECT uid,MIN(DATE(in_time)) AS dt FROM tb_user_log GROUP BY uid), # 新用户表t2 AS (SELECT uid, DATE(in_time) as active_timeFROM tb_user_logUNIONSELECT uid, DATE(out_time) as active_timeFROM tb_user_logUNIONSELECT uid, (DATE(in_time)+ INTERVAL 1 DAY) as active_time # 跨天活跃FROM tb_user_logWHERE TIMESTAMPDIFF(DAY,in_time,out_time)>=1) # 用户活跃日期表SELECT t2.active_time, COUNT(t2.uid) AS dau, ROUND(COUNT(t1.uid)/COUNT(t2.uid),2) AS uv_new_ratioFROM t2LEFT JOIN t1 ON t1.uid = t2.uid and t1.dt = t2.active_timeGROUP BY active_timeORDER BY active_time