我有三张桌子School, Grade, Student.表Grade具有Foreign Key列s_id上引用Primary Key列id的School和表Student具有Foreign Key列g_id上引用Primary Key列id表中的Grade.我需要选择school_name,高度低于170或高于180的学生人数.现在,我写这样的选择查询.
SELECT School.name, School.id as sid,
(Select count(*) from Student inner join Grade on
Student.g_id=Grade.id inner join School on
Grade.s_id=School.id where School.id=sid and
Student.height < 170) as under_170,
(Select count(*) from Student inner join Grade on
Student.g_id=Grade.id inner join School on
Grade.s_id=School.id where School.id=sid and Student.height > 180) …Run Code Online (Sandbox Code Playgroud)