|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Average of a Count
I am trying to take the average number of students in a class by counting their school_id's but there are multiple classes that are being taught. Any ideas?
This is what i have SQL> SELECT AVG(COUNT(S.STUDENT_ID)) AS STUDENTS_PER_CLASS 2 FROM STUDENTS S, STUDENT_CLASS U, CLASS C, TEACHER T 3 WHERE S.STUDENT_ID = U.STUDENT_ID AND U.CLASS_ID = C.CLASS_ID 4 AND C.TEACHER_ID = T.TEACHER_ID 5 GROUP BY S.STUDENT_ID; What is wrong with this? |
|
#2
|
||||
|
||||
|
You really need just one table, if you have difficulties visualizing the results use two queries, the first one (nested) will get the count per class, the second (outer one) will average those counts
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
|
#3
|
|||
|
|||
|
Quote:
Is that not what I am doing my first one (nested)is getting the count for the class and the outer one is averaging right? |
|
#4
|
||||
|
||||
|
No
|
|
#5
|
||||
|
||||
|
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Average of a Count |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|