SQL Average始终返回0

时间:2013-06-12 15:05:07

标签: sql

我有一个简单的SQL命令:

SELECT Avg('observations1') AS AvgFeedback,
       Avg('observations2') AS AvgChallenge,
       Avg('observations3') AS AvgTalk,
       Avg('observations4') AS AvgSkills,
       Avg('observations5') AS AvgExpectations
FROM   .observations
WHERE  obsschool = 'admin';  

但是,当每个字段中都有数字时,每个结果都为0。我究竟做错了什么?感谢。

2 个答案:

答案 0 :(得分:8)

删除包含字段名称的引号('):

SELECT Avg(observations1) AS AvgFeedback,
       Avg(observations2) AS AvgChallenge,
       Avg(observations3) AS AvgTalk,
       Avg(observations4) AS AvgSkills,
       Avg(observations5) AS AvgExpectations
FROM   observations
WHERE  obsschool = 'admin'; 

传递字段名称时,不需要引号。

答案 1 :(得分:0)

你可以尝试一下,看看你得到了什么结果?:

avg(cast(observations1 as dec(7,5))) as AvgFeedback