这题感觉牛客有,我是用的窗口函数做的。小白浅写,请大佬多多批评指教。 with tiaojian as ( select uid,in_time as pday from 实录表 union all select uid,out_time as pday from 实录表 ) select t.pday, sum(case when t.m=1 then 1 else 0 end), round( sum(case when t.m=1 then 1 else 0 end)/count(distinct t.uid),2) from( select uid, pday, row_number()over(partition by uid order by pday asc) as m from tiaojian ) as t group by t.pday