一个sql语句问题(急)

来源:百度知道 编辑:UC知道 时间:2024/05/12 03:36:04
表1:student
sno(学号) name(名字) prize(奖学金)
001 jim 200
002 susan 300
003 jack null
表2:subject
cno(课程编号) subname(课程)
1 语文
2 数学
3 英语
表3:total
sno(学号) cno (课程编号) score(分数)
001 1 90
001 2 80
001 3 70
002 1 85
002 2 67
002 3 77
003 1 89
003 2 87
003 3 86
请查询出各科分数都超过该科目平均分的同学的名字?

先把各科平均成绩存如table1中
select cno , avg(score) as avgscore into table1 from total group by cno
再找各科成绩都大于平均成绩的学生的名字
select [name] from student where sno in (select sno from total a, table6 b where a.cno=b.cno and a.score>b.avgscore)