我有两张 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/