1

我有一个简单的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。我究竟做错了什么?谢谢。

4

2 回答 2

9

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

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'; 

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

于 2013-06-12T15:06:21.543 回答
0

你可以试试这个,看看你得到什么结果?:

avg(cast(observations1 as dec(7,5))) as AvgFeedback
于 2013-06-12T15:11:32.750 回答