select id from ( select id, round((unix_timestamp(e_time) - unix_timestamp(time_lag)) / 60,1) minute from (select *,lag(e_time,5)over(parition by id order by e_time)time_lag from table)a where round((unix_timestamp(e_time) - unix_timestamp(time_lag)) / 60,1)<=5 )b group by id 1、子查询a是利用窗口滑动,来计算用户第N次的登录时间,time_lag取决于我要滑动几次,下面示例是滑动两次 id e_time time_lag 1 1name 1:00 2 2name 1:01 3 3name 1:02 1:00 4 4name 1:03 1:01 5 5name 1:04 1:02 2、子查询B是吧时间转成成面数以后做计算转成分钟 3、最后的查询是用来去重,因为一个用户5分钟如果要是登录的上百次,那么会统计出很多次符合规则的计算,所以去重