这将是容易得多,如果我能有一个样本这里这些表的,但试试这个
SELECT
answers.id AS 'answer id',
count(attempts.id) AS 'number of attempts'
FROM
question_attempts AS attempts
JOIN
question_answers AS answers ON answers.answer = attempts.responsessummary
WHERE
question_answers.question = 1
GROUP BY
answers.id;
,如果它工作正常,你应该得到的答案ID的表,尝试对这个问题的答案的数目。
但是您需要在这两个字段中完全匹配。从question_attempts和question_answers的responsessummary回答问题。
,如果它不可能解决方法是使用LIKE条款:
SELECT
answers.id AS 'answer id',
count(attempts.id) AS 'number of attempts'
FROM
question_attempts AS attempts
JOIN
question_answers AS answers ON answers.answer
LIKE CONCAT('%', attempts.responsessummary , '%')
WHERE
question_answers.question = 1
GROUP BY
answers.id;
来源
2015-06-18 10:54:41
Ali
你尝试过什么了吗?你应该可以(内部)加入这两个表并且计数 – Ali
不使用内部连接。echo $ data = mysql_num_rows(“从question_attempts'选择count('respondummary'),其中'questionid' = 4 AND'respondummary' = 43152”); 这是我写的代码。它在phpmyadmin中显示, – JRK
但是,尝试在页面中显示时不显示。 – JRK