我有以下问题,我有2张桌子:
Surveys (surveyID, topic, text)
Response (responseID, response_text, response_value)
我的问题如下:如何获得每个调查的平均答复数?
假设我有2个SurveyID
和8个AnswerID
,如何将8个responseID
除以2个surveyID
?
我的想法是,但这没有解决:
SELECT (COUNT(surveyID) / COUNT(responseID))
FROM Surveys, Response;
答案 0 :(得分:0)
您可以尝试使用sql-serevr:
with x as(
Select count(*) as totSurveys, 0 as TotResponse
from Surveys
union
Select 0 as totSurveys, count(*) as TotResponse
from Response
) select TotResponse/totSurveysas Result
from x
或者您可以:
select (Select count(*) from Surveys)/(Select count(*) from Response)
答案 1 :(得分:0)
要明确说明您的问题:
SELECT (COUNT(distinct surveyID) / COUNT(distinct responseID))
FROM Surveys, Response;
(不同的指令指示DBMS仅计算结果中的唯一值)
答案 2 :(得分:0)
SELECT (COUNT(distinct surveyID) / COUNT(distinct
responseID))
FROM Surveys, Response
唯一的原因是 意外的输出是单独的重复项 您的 表使用此功能,您将获得所需的