题解 | #每篇文章同一时刻最大在看人数#

每篇文章同一时刻最大在看人数

http://www.nowcoder.com/practice/fe24c93008b84e9592b35faa15755e48

  • 对于同样一个类型的字段,可以采用编码+联立的方式来求取同样一个时间在线的人数
  • 对于同时进出的,要先统计进的,再统计出的
select artical_id, max(user_cnt) from (
select artical_id, t,
sum(diff) over(partition by artical_id order by t asc, diff desc) user_cnt
from (
select artical_id artical_id, in_time t, 1 diff from tb_user_log 
where artical_id != 0 
union all 
select artical_id artical_id, out_time t, -1 diff from tb_user_log
where artical_id != 0 ) t1
) t2
group by 1
order by 2 desc 
全部评论

相关推荐

感性的干饭人在线蹲牛友:🐮 应该是在嘉定这边叭,禾赛大楼挺好看的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务