题解 | 统计创作者

统计创作者

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

with
    t as (
        select
            author_id,
            count(distinct title) posts_30d,
            sum(like_cnt) likes_30d
        from
            (
                select
                    author_id,
                    title,
                    like_cnt,
                    dense_rank() over (
                        partition by
                            author_id
                        order by
                            left(publish_ts, 7) desc
                    ) as ts_rank
                from
                    post
            ) tmp
        where
            ts_rank between 1 and 30
        group by
            tmp.author_id
    )
select
    a.author_id,
    a.author_name,
    posts_30d,
    likes_30d,
    ifnull(round(likes_30d / posts_30d, 2), 0) avg_likes_30d
from
    author a
    left join t using (author_id)
where
    posts_30d > 0
order by
    likes_30d desc,
    posts_30d desc,
    a.author_id
limit
    5

全部评论

相关推荐

01-26 19:51
门头沟学院 Java
isabener:怎么感觉像群发的呢
点赞 评论 收藏
分享
牛客66512506...:那个百度acg是不是个小哥啊,老是问些底层问题狠狠为难,然后kpi
哪些公司在招寒假实习?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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