RGriffiths
RGriffiths

Reputation: 5970

SQL Average always returns 0

I have a simple SQL command:

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

However every result is 0 when there are numbers in each of the fields. What am I doing wrong? Thanks.

Upvotes: 2

Views: 2435

Answers (2)

Learner
Learner

Reputation: 4004

Can you try this and see what results you get?:

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

Upvotes: 1

haim770
haim770

Reputation: 49095

Remove the quotes (') wrapping your field names:

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

When passing field names, no quotes necessary.

Upvotes: 10

Related Questions