我正在尝试计算所选列的平均值。
如果我运行此代码:
SELECT answer_value
FROM survey$question$answer JOIN answer
ON survey$question$answer.answer_letter = answer.answer_letter
WHERE survey$question$answer.survey_id = 12;
但是,当我运行此命令时:
SELECT AVG(answer_value)
FROM survey$question$answer JOIN answer
ON survey$question$answer.answer_letter = answer.answer_letter
WHERE survey$question$answer.survey_id = 12;
我得到2的平均值,而正确的5、5和3平均值是4.33
为什么会这样?
另一个例子。这段代码在这里:
SELECT answer_value
FROM survey$question$answer JOIN answer
ON survey$question$answer.answer_letter = answer.answer_letter
WHERE survey$question$answer.survey_id = 6;
但是当我尝试使用此代码计算平均值时:
SELECT AVG(answer_value)
FROM survey$question$answer JOIN answer
ON survey$question$answer.answer_letter = answer.answer_letter
WHERE survey$question$answer.survey_id = 6;
3、2和1的平均值等于2,而不是9.33
帮助?
谢谢!
答案 0 :(得分:0)
我认为您错了,您在以下其他地方确实犯了错误,请检查表列的数据类型
select avg( c) from (select 5 as c
union all
select 5
union all
select 3
) a
c
4.3333
答案 1 :(得分:0)
我首先有answer_value
作为一组数字。
后来我将answer_value
更改为INT,但是忘记删除并重新创建表。 >。<< br />
现在我做的很好。
谢谢您的时间,对不起我的迟钝...