select
t.dt,
round(count(distinct a.uid) / count(distinct t.uid),2) as uv_left_rate
from
(
select
date (min(in_time)) as dt,
uid
from
tb_user_log
group by
uid
) t
left join (
select
uid,
date (in_time) as dt
from
tb_user_log
union
select
uid,
date (out_time) as dt
from
tb_user_log
) a on
t.uid = a.uid
and t.dt = date_sub(a.dt,interval 1 day)
where
date_format(t.dt, '%Y-%m') = '2021-11'
group by
t.dt
order by
t.dt
很唐的格式化,空格会导致函数不能运行,题目主要考了union跨天



京公网安备 11010502036488号