全部评论
字节也考过原题。。。
我觉得可能是这样? select count(uid)as 在线人数 from (select uid,timestampdiff(second,begin_time,end_time)as时间间隔 from 表)t where 时间间隔 = 1
这题蛮简单的啊。。。
mark
插眼……按秒列的话岂不是会有很多行么?第一反应是按每一秒写case when,但是这样得写到哪年去……
SQL这么可怕的吗。。。我之前遇到这个题的时候是编程题啊... 用一个数组记录每一秒的上下线人数,对这个数组求前缀和,每个位置的值就是当前的在线人数了。SQL不知道能不能按这个思路来哈哈
不知这样是否可以?
select dt_time,count(disinct uid) from ( select uid,begin_time,end_time from a )a cross join bp.yyzc_dt b ---秒级别时间维表 where b.dt_time between begin_time and end_time group by dt_time
相关推荐

点赞 评论 收藏
分享

点赞 评论 收藏
分享