响应标头表是一个连接表,计算该表以显示对特定调查的响应。如果没有行,因此没有响应,我希望计数显示0.但是它正在跳过该行,因为在表中找不到连接parm(survey_id)。
SELECT DATE_FORMAT(launched_date,'<nobr>%e-%b-%Y %H:%i:%s</nobr>'),
survey.NAME,
survey.iris_type,
survey.launched_by,
COUNT(response_header_2010.survey_id) AS response_count,
survey.survey_id,
survey.NAME
FROM survey, response_header_2010
WHERE survey.STATUS='Live'
AND survey.iris_type!='Recipient List'
AND response_header_2010.survey_id = survey.survey_id
AND client_id = '98'
GROUP BY survey.survey_id, survey.NAME
ORDER BY response_count
答案 0 :(得分:2)
您想使用LEFT JOIN而不是您目前拥有的INNER JOIN。
SELECT DATE_FORMAT(launched_date,'<nobr>%e-%b-%Y %H:%i:%s</nobr>'),
survey.NAME,
survey.iris_type,
survey.launched_by,
COUNT(response_header_2010.survey_id) AS response_count,
survey.survey_id,
survey.NAME
FROM survey
LEFT JOIN response_header_2010
ON survey.survey_id = response_header_2010.survey_id
WHERE survey.STATUS='Live'
AND survey.iris_type!='Recipient List'
AND client_id = '98'
GROUP BY survey.survey_id, survey.NAME
ORDER BY response_count