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

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

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


WITH t1 AS (SELECT uid,artical_id,in_time dt,1 diff FROM tb_user_log WHERE artical_id <> 0	
		UNION
		SELECT uid,artical_id,out_time dt,-1 diff FROM tb_user_log WHERE artical_id <> 0	),
    t2 as(
      
		SELECT 
		artical_id, 
    	sum(diff) over ( PARTITION BY artical_id ORDER BY dt ,diff desc) as sum_diff
		FROM t1)
SELECT
	artical_id,max(sum_diff) max_uv
FROM
	t2
GROUP BY
	artical_id
ORDER BY
	max_uv desc


全部评论

相关推荐

像好涩一样好学:这公司我也拿过 基本明确周六加班 工资还凑活 另外下次镜头往上点儿
点赞 评论 收藏
分享
粗心的雪碧不放弃:纯学历问题,我这几个月也是一直优化自己的简历,后来发现优化到我自己都觉得牛逼的时候,发现面试数量也没有提升,真就纯学历问题
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务