【发布时间】:2015-02-24 22:10:37
【问题描述】:
我正在研究的问题是:
提供按省份和问题细分的问题的平均答案。您必须包括省份和问题以及平均值。
示例输出看起来像这样:
Ontario - Do you like blak? - 3.4
Ontario - Do you like flah? - 2.3
Ontario - Do you like rahhggg? - 4.8
Alberta - Do you like flah? - 2.3
Alberta - Do you like rahhggg? - 4.8
到目前为止,我已尝试按问题将它们与平均值一起列出,但我不知道如何首先按省份对其进行分组。我认为这是一个 JOIN,但我不知道如何布局。我有什么:
SELECT survey_question_id, AVG(survey_response)
FROM survey_responses
JOIN survey_responders
ON survey_responses.id = survey_responders.id
WHERE survey_responders.province='Ontario'
GROUP BY survey_question_id;
【问题讨论】: