Mysql SQL将计数(从2个表)添加到现有select(共3个表)
对论坛数据库进行查询。我使用此查询获取线程名称、海报、日期等 (现在只剩下线程主题) 基本上,我还需要在现有的select中添加类似下面的count的内容,以计算每个线程的帖子数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
选择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