I have three tables.
- table
SCHOOL: schoolcode(PK), year, schoolname. - table
ENROLMENT: schoolcode, year, classname, enrol - table
CLASS: schoolcode, year, classid, rooms
Now, I want to find the list of schools with enrollment in classname - 1 to 4 and number of classrooms used by class 1-4.
I used the following query:
select
m.schoolcode, m.schoolname, sum(e.c1+e.c2+e.c3+e.c4), sum(c.rooms)
from
dise2k_enrolment09 e, dise2k_master m, dise2k_clsbycondition
where
m.schoolcode = e.schoolcode
and m.schoolcode = c.schoolcode
and e.year = '2011-12' and m.year = '2011-12' and c.year = '2011-12'
and classid in (1,2,3,4)
and e.classname in (1,2,3,4)
group by
m.schoolcode, m.schoolname
but the result showing is not correct. Enrollment is showing much higher than actual, same in case of classrooms.