Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.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/5/sql/87.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
Mysql SQL将计数(从2个表)添加到现有select(共3个表)_Mysql_Sql_Select_Join_Count - Fatal编程技术网

Mysql SQL将计数(从2个表)添加到现有select(共3个表)

Mysql SQL将计数(从2个表)添加到现有select(共3个表),mysql,sql,select,join,count,Mysql,Sql,Select,Join,Count,对论坛数据库进行查询。我使用此查询获取线程名称、海报、日期等 (现在只剩下线程主题) 基本上,我还需要在现有的select中添加类似下面的count的内容,以计算每个线程的帖子数 选择COUNT(*)作为fusion\u posts、fusion\u threads的后计数,其中fusion\u threads.thread\u id=fusion\u posts.thread\u id按fusion\u threads.thread\u id分组 我该怎么做呢?试试这个:- SELECT `t

对论坛数据库进行查询。我使用此查询获取线程名称、海报、日期等

(现在只剩下线程主题)

基本上,我还需要在现有的select中添加类似下面的count的内容,以计算每个线程的帖子数

选择COUNT(*)作为fusion\u posts、fusion\u threads的后计数,其中fusion\u threads.thread\u id=fusion\u posts.thread\u id按fusion\u threads.thread\u id分组

我该怎么做呢?

试试这个:-

SELECT `thread_subject`, COUNT(*) AS PostCount 
FROM `fusion_posts` JOIN `fusion_threads`
ON fusion_posts.thread_id=fusion_threads.thread_id JOIN `fusion_users` 
ON fusion_posts.post_author=fusion_users.user_id 
GROUP BY fusion_posts.thread_id, `thread_subject` 
ORDER BY `post_id` DESC 
LIMIT 16

选择线程\u主题,计数(*)从…
谢谢!:)(符号不够)
SELECT `thread_subject`, COUNT(*) AS PostCount 
FROM `fusion_posts` JOIN `fusion_threads`
ON fusion_posts.thread_id=fusion_threads.thread_id JOIN `fusion_users` 
ON fusion_posts.post_author=fusion_users.user_id 
GROUP BY fusion_posts.thread_id, `thread_subject` 
ORDER BY `post_id` DESC 
LIMIT 16