0

I'm trying to forumlate a query which will give me this result:

For each quiz number list the quiz number and the average high score. Only include the quizzes that more than 10 students took.

The query I am formulating looks like this:

SELECT QuizNum, AVG(HighScore) from quizzes WHERE NumStudents > 10;

This, however, gives me :

1, 20.75000

Which is incorrect data. I just really don't know where to start with this one.

The table looks like this:

'QuizNum', 'decimal(2,0)', 'NO', 'PRI', '0', ''
'QuizDate', 'date', 'NO', 'PRI', '0000-00-00', ''
'HighScore', 'decimal(3,1)', 'YES', '', '', ''
'LowScore', 'decimal(3,1)', 'YES', '', '', ''
'AvgScore', 'decimal(3,1)', 'YES', '', '', ''
'NumStudents', 'int(11)', 'YES', '', '', ''
'NumPassing', 'int(11)', 'YES', '', '', ''

So, foe example, every date quiz one occured has more than 10 students, so I need its average. Then I need the next quiz. Table Contents:

1, '2009-01-25', 20.0, 9.0, 12.5, 15, 10
1, '2009-06-15', 30.0, 22.0, 25.6, , 
1, '2009-08-25', , , , 15, 10
1, '2010-01-24', 20.0, 9.0, 12.5, 17, 14
1, '2010-06-14', 28.5, 21.0, 26.6, 25, 25
1, '2010-08-24', , , , 21, 18
2, '2009-03-06', 18.0, 10.5, 15.0, 15, 12
2, '2009-07-01', 28.5, 18.5, 23.4, , 
2, '2009-09-21', 18.0, 10.5, 15.0, 15, 12
2, '2010-03-05', 18.5, 11.5, 15.2, 17, 14
2, '2010-06-30', 30.0, 25.0, 27.4, 23, 23
2, '2010-09-20', , , , 22, 19
3, '2009-03-24', 19.0, 14.5, 17.8, 13, 13
3, '2009-08-01', 27.5, 25.0, 16.2, , 
3, '2009-10-12', 19.0, 14.5, 17.8, 13, 13
3, '2010-03-23', 20.0, 17.0, 18.6, 16, 16
3, '2010-07-31', , , , 23, 20
3, '2010-10-11', 20.0, 9.0, 13.8, 22, 17
4, '2009-04-14', 20.0, 15.5, , , 
4, '2009-11-22', 20.0, 15.5, 17.9, , 
4, '2010-04-13', 20.0, 12.5, , , 
4, '2010-11-21', 20.0, 7.5, 13.9, 20, 15
5, '2009-05-04', 17.0, 8.5, 10.7, 10, 7
5, '2009-12-09', 17.0, 8.5, 10.7, 10, 7
5, '2010-04-03', 19.5, 11.5, 15.7, 15, 13
5, '2010-12-08', 20.0, 15.0, 17.3, 18, 18

Ideas?

2
  • Expected output? what is NumStudents?
    – Sadikhasan
    Jul 11, 2014 at 3:17
  • I will update the question to show you the table contents. There are 5 numbers of quizzes. For each quiz number, I need the quiznumber and average of the high score column. Only for quizzes where more than 10 students took the quiz. I just dont know how to iterate over a column in this fasion. Jul 11, 2014 at 3:19

2 Answers 2

2

For each quiz number

You need a GROUP BY:

SELECT QuizNum, AVG(HighScore) 
FROM quizzes 
WHERE NumStudents > 10 
GROUP BY QuizNum;
2

You have to use GROUP BY clause like

SELECT QuizNum,
       AVG(HighScore)
FROM quizzes
WHERE NumStudents > 10
GROUP BY QuizNum;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.