Click to See Complete Forum and Search --> : Average of score field obtained from Database


mpd100
04-27-2006, 03:53 AM
I need to create a function that calculates average score of users in a quiz,

The results are held in a field in the results table called score. I'm using SQL Server DB.

Can anyone help with sample code:

schizo
04-27-2006, 06:59 PM
Just use the AVG function...

SELECT AVG(score) AS avgScore FROM results WHERE userID = 5

handshakeit
04-28-2006, 06:28 AM
The field must be numeric type in DB to use AVG function
SELECT AVG(field) FROM score;