我觉得可能是这样? select count(uid)as 在线人数 from (select uid,timestampdiff(second,begin_time,end_time)as时间间隔 from 表)t  where 时间间隔 = 1