【问题标题】:Sort Author Names by Post Count按帖子计数排序作者姓名
【发布时间】:2016-04-04 21:33:09
【问题描述】:

我有两张桌子。

作者

Author_ID      Author_Name               
 -------------------------                      
1           name 1      
2           name 2    
3           name 3
 ---------------------------

发布

Post_ID      Author_ID
 -------------------------                      
1           1      
2           1    
3           2
4           3
5           3
6           3
 ---------------------------

我需要一个 mysql 查询来计算每个作者拥有的帖子数量,然后将作者从大到小排序。

我当前的 MySQL 只显示名称:

select * from AUTHOR
where author_status = '1' ORDER BY author_name DESC

【问题讨论】:

    标签: mysql


    【解决方案1】:
    SELECT author.author_id, author.author_name, count(post.post_id) FROM AUTHOR, POST
        WHERE (author_status = '1')
        AND (author.author_id = post.author_id) 
    GROUP BY author.author_id
    ORDER BY author.author_name DESC;
    

    【讨论】:

    • 我删除了 ORDER BY 行,这给了我想要的结果。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多