Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 AVG problematic

Author  Topic 

Gaberiele
Starting Member

3 Posts

Posted - 2007-10-10 : 07:04:42


My table is this:

id_voto int key;
pulizia int
accoglienza int
condizioni int
confort int

the query is:

SELECT avg( pulizia & accoglienza & condizioni & confort )
FROM votazioni
WHERE id_voto =10

they do not give to error but not even the average correct!

Which it is the problem?

Thanks!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-10 : 07:06:40
SELECT avg( pulizia + accoglienza + condizioni + confort )
FROM votazioni
WHERE id_voto =10

SELECT avg( pulizia ), avg( accoglienza ), avg( condizioni ), avg( confort )
FROM votazioni
WHERE id_voto =10



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Gaberiele
Starting Member

3 Posts

Posted - 2007-10-10 : 07:15:46
the first too much give an elevated number to me

the second give the value of pulizia,....: 4 6 6 7

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-10 : 07:30:50
SELECT ( pulizia + accoglienza + condizioni + confort ) / 4.0
FROM votazioni
WHERE id_voto = 10



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-10 : 07:37:46
Make sure you handle NULLs

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Gaberiele
Starting Member

3 Posts

Posted - 2007-10-10 : 10:16:35
quote:
Originally posted by Peso

SELECT ( pulizia + accoglienza + condizioni + confort ) / 4.0
FROM votazioni
WHERE id_voto = 10




this is the solution!

thanks!
Go to Top of Page
   

- Advertisement -