Sql查询语句

来源:百度知道 编辑:UC知道 时间:2024/06/22 00:20:43
一个班级表,一个分数表,一个学生表,一个科目表
查询结果要求在查询分析器里显示
班级 60分以下 60-80分 80-100分
一班 (多少人) (多少人) (多少人)
二班 (多少人) (多少人) (多少人)
依次类推
class表 列:id int,class varchar(50),code varchar(50)
score表 列:id int,studentid int ,subjectid int ,score decimal(18,2)
student表 列: id int ,sutudent varchar(50),class int ,code varchar(50)
class表的id列student表的class关联
student表的id 列和score表的studentid关联

科目不要了..
只有这3个表,我自己写子查询迷糊了,谁能写出来哇0 0

select tb2.*,tb100.count100
from
(select tb1.*,tb80.count80
from
(select class.id, class.class,tb60.count60
from class
left join
(select classid,count(studentid) as count60 from score group by classid where score<60) as tb60
on class.id=tb60.id) as tb1
left join
(select classid,count(studentid) as count80 from score group by classid where score<80 and score>=60)as tb80
on tb1.id=tb80.classid) as tb2
left join
(select classid,count(studentid) as count100 from score group by classid where score>=80) as tb100
on tb2.id=tb100.classid

搞定~

需要4张表的表结构,你需要再说明下,这四张表分别有什么关联。
最好再贴出一点例样数据

表结构都没弄出来怎么写啊