mysql - 按帖子计数对作者姓名排序

标签 mysql

我有两张 table 。

作者

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

最佳答案

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;

关于mysql - 按帖子计数对作者姓名排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36413284/

相关文章:

php - 无法使用用户名和密码连接到数据库

java - 如何使用java在一定时间后自动将数据存储到mySql数据库?

mysql - mysql中的 "three way data binding"怎么办?

php - 找出您的 PHP 代码在哪里变慢(性能问题)

php - 更新数据库架构时不允许使用空值

MySQL排序数问题

mysql - 将 session 中一位用户的消息标记为已删除

php - MySQL从5.0升级到5.5后的查询时间

mysql - 查找与某个类别进行过交互的重复用户的数量

python - Django MySql,外键查询