题解 | #计算每天的有点比和query平均点击数#

计算每天的有点比和query平均点击数

https://www.nowcoder.com/practice/6dbd771ff92b4c6db334714c01718101

#还是先吐槽发布的题意没读懂。
#题意在用户在search_log_tb这表的,event_time时间与之后的时间之前,点击的情况。
#我之前有个想法,就是直接整天全求出来,后来发现要判断每天点击不为空的次数,因此,要求每人每个时间段的次数,然后在一层求有效点击和均点击值


with tiaojian as (
select 
uid,
event_time,
lead(event_time,1,(select max(event_time) from search_log_tb))over(partition by uid order by event_time asc) as m 
from search_log_tb
)

select 
date(t.event_time) as dt,
round(
avg(case when cnt>0 then 1 else 0 end),3) as click_rate,
round(
avg(cnt),3) as avg_click_cnt
from(
select 
t.uid,
t.event_time,
count(tb.id) as cnt
from tiaojian t left join click_log_tb tb on t.uid=tb.uid
and  tb.event_time between t.event_time and t.m
group by t.event_time,t.uid
) as t 
group by dt

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 11:30
仁者伍敌:kpi都懒得刷了属于是
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务