私は3つのテーブルを持っています。
SCHOOL: 学校コード (PK)、年、学校名。
登録: schoolcode, year, caste, c1, c2, c3, c4, c5, c6, c7, c8
CLASS: schoolcode, year, classid, rooms
ここで、クラス 1 から 4 に在籍する学校のリストと、クラス 1 から 4 が使用する教室の数を検索したいと考えています (CLASSID は次のように定義されます: クラス 1 と 2 の場合は 7、クラス 3 と 4 の場合は 8、クラスの場合は 9)。 5&6、クラス 7&8 は 10、カーストは一般に 1、sc に 2、st に 3、その他に 4 と定義されます)。
次のクエリを使用しました。
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 c
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
c.classid in(7,8) and
e.caste in(1,2,3,4)
group by m.schoolcode, m.schoolname
しかし、表示される結果は正しくありません。入学者数は、教室の場合と同様に、実際よりもはるかに多くなっています。