Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql选择具有更多帖子的作者_Php_Mysql - Fatal编程技术网

Php Mysql选择具有更多帖子的作者

Php Mysql选择具有更多帖子的作者,php,mysql,Php,Mysql,我的数据库中有两个表:tb_作者和tb_帖子 我需要显示一个作者列表,按每个作者的帖子数量降序排列 两个表都有一个共同的id\u author键 有人能帮我吗 好的,到目前为止我得到了这个: SELECT tb_authors.*, COUNT(tb_posts.*) AS thecount FROM tb_posts, tb_authors WHERE tb_authors.id_author = tb_posts.id_author ORDER BY thecount DESC; 但它不起

我的数据库中有两个表:tb_作者和tb_帖子

我需要显示一个作者列表,按每个作者的帖子数量降序排列

两个表都有一个共同的
id\u author

有人能帮我吗

好的,到目前为止我得到了这个:

SELECT tb_authors.*, COUNT(tb_posts.*) AS thecount FROM tb_posts, tb_authors WHERE tb_authors.id_author = tb_posts.id_author ORDER BY thecount DESC;

但它不起作用。它返回一个包含一个作者的列,count具有posts总数的值。

奇怪的是,表名和公共键足以回答这个问题

SELECT tb_authors.*, COUNT(tb_posts.*) AS thecount WHERE tb_posts.id_author = tb_authors.id_author ORDER BY thecount DESC

你以前做过任何关系查询吗?我仍在试图找出如何同时选择和计算。嘿,谢谢你的帮助!它在“*)附近返回一个语法错误作为计数。嗯,我遗漏了一些东西(这也不是我经常做的查询)。尝试阅读以下帖子: