【问题标题】:Web Articles/Comments Counts网络文章/评论计数
【发布时间】:2014-07-02 18:46:11
【问题描述】:

我如何列出在发生页面浏览时平均拥有最多 cmet 的前 10 篇文章。

SELECT  TOP 10 a.title as 'articles'
FROM    articles a 
JOIN    website_pageviews b on a.id = b.article_id
JOIN    comments c on a.id = c.commented_article_id 
GROUP BY a.id

我已经做到了这一点,但我现在有点迷茫 - 我该如何做“平均”部分。

我的表格如下

table: website_pageviews (timestamp, article_id, visitor_id, and a bunch of others)
table: articles (id, title, timestamp, content, author, subject)
table: comments (commented_article_id, user_id, timestamp, text)

我在哪里使用最大值或平均值? 请帮忙...谢谢!

【问题讨论】:

    标签: sql select web max average


    【解决方案1】:
    SELECT  TOP 10 a.title as articles,
            count(c.commented_article_id) * 100 / count(b.visitor_id) as percentage
    FROM    articles a 
    JOIN    website_pageviews b on a.id = b.article_id
    JOIN    comments c on a.id = c.commented_article_id 
    GROUP BY a.id, a.title
    order by count(c.commented_article_id) * 100 / count(b.visitor_id) desc
    

    【讨论】:

    • 使用 'order' by 就够了吗?我不需要嵌套选择?还是更复杂的?
    • 这是您获取所有 cmets 最多的文章列表的方式。或者你说的平均是什么意思?
    • 问题是“我如何列出在发生页面浏览时平均拥有最多 cmets 的前 10 篇文章。我不是 100% 确定这意味着什么。
    • 你问了这个问题。如果有人知道这意味着什么,那就是你。
    • 触摸。可悲的是,我希望是这样 :-) 但我认为这是对我的要求。感谢您的帮助。
    猜你喜欢
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2016-11-10
    • 2015-09-14
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多