gpt4 book ai didi

mysql - 计算连接表中的行数,但如果不存在行则显示 0 - mysql

转载 作者:行者123 更新时间:2023-11-29 07:10:45 24 4
gpt4 key购买 nike

响应标题表是一个连接表,计算该表以显示对特定调查的响应。如果没有行,因此没有响应,我希望计数显示 0。但它会跳过该行,因为在表中找不到连接参数 (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

最佳答案

您想使用 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

关于mysql - 计算连接表中的行数,但如果不存在行则显示 0 - mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4686003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com