MYSQL多连接计数
基本数据模型: 嗨,谢谢你的帮助 我想查询一门课程的问题数和答案数MYSQL多连接计数,mysql,join,count,Mysql,Join,Count,基本数据模型: 嗨,谢谢你的帮助 我想查询一门课程的问题数和答案数 SELECT courses.name, courses.description, courses.digest, courses.views, categories.icon, COUNT(answers.id), COUNT(problems.id) FROM courses INNER JOIN topics ON topics.id = courses.topics_id
SELECT
courses.name,
courses.description,
courses.digest,
courses.views,
categories.icon,
COUNT(answers.id),
COUNT(problems.id)
FROM
courses
INNER JOIN
topics ON topics.id = courses.topics_id
INNER JOIN
categories ON categories.id = topics.categories_id
LEFT JOIN
problems ON problems.courses_id = courses.id
LEFT JOIN
answers ON answers.problems_id = problems_id
WHERE
courses.accounts_id = 1
GROUP BY courses.id
但这是行不通的,有什么想法吗
thx可能是一个输入错误,但在您上次加入时,您正在进行
answers.problems\u id=problems\u id
在问题表或除答案表之外的任何其他表中,您都没有问题\u id
列
是否应该是
问题。id
?错误消息或意外行为是否已分类?如果没有,请与我们分享。可能是输入错误,但在您上次加入时,您正在执行答案。problems\u id=problems\u id
是否正确?应该有问题吗?谢谢!我把它改为problems.id,但我仍然在做一个新的查询来查询答案。