题解 | 统计创作者

统计创作者

https://www.nowcoder.com/practice/5f0155102879494c8707f749156f9af3

select
*
from (
    select
post.author_id 
,author_name 
,count(1) posts_30d 
,sum(like_cnt) likes_30d 
,ifnull(ROUND(sum(like_cnt) / count(1), 2),0) avg_likes_30d
from author join post on post.author_id = author.author_id
where date_format(publish_ts,'%Y-%m-%d')
between 
date_sub((select
date_format(publish_ts,'%Y-%m-%d')
from (
    select
    publish_ts    
    ,row_number()over(order by publish_ts desc) rk
    from author join post on post.author_id = author.author_id
) t1
where rk = 1),interval 30 day) 
and 
(select
date_format(publish_ts,'%Y-%m-%d')
from (
    select
    publish_ts    
    ,row_number()over(order by publish_ts desc) rk
    from author join post on post.author_id = author.author_id
) t1
where rk = 1)
group by 1,2
) t2
where posts_30d > 0
order by 4 desc,3 desc,1
limit 5

全部评论

相关推荐

09-18 20:41
阿里巴巴_后端
要个offer怎么这...:哈哈哈哈哈哈,我也拿了0x10000000个offer,秋招温啦啦啦,好开心
我的秋招日记
点赞 评论 收藏
分享
自来熟的放鸽子能手面...:这个不一定,找hr跟进一下
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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