我有 2 张 table :
表 1:问题
:
-Id
-Name
-AdditionalInformation
-Author
-QuestionCategory
-Date
-Time
表 2:注释
:
- Id
- QuestionId
我需要得到Question
中的所有表格以及每个QuestionID的评论数。
有人可以帮忙吗?
我尝试过的:
select * from Questions
union
SELECT Count(ID) FROM Comments Group By QuestionId
最佳答案
select q.*, c.commentCount
from questions q left join
(select questionid, count(id) as commentCount
from comments
group by questionid
) c
on c.questionid = q.id
关于mysql - 我想将 2 个 SQL 查询合并到一个查询中 - 带计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34091033/