数据库表结构和数据见我的上一篇博文
1.查询"01"课程比"02"课程成绩高的学生的信息和课程分数
select s.* ,a.s_score
from Score a,Score b,Student s
where s.s_id = a.s_id
and a.s_id = b.s_id
and a.c_id = "01"
and b.c_id = "02"
and a.s_score > b.s_score;
结果:
s_id s_name s_birth s_sex s_score
02 钱电 1990-12-21 男 70
04 李云 1990-08-06 男 50
2.查询平均成绩小于60分的学生的信息和平均成绩
select b.* ,avg(a.s_score)
from Score a join Student b
on a.s_id = b.s_id
group by a.s_id
having avg(a.s_score)<60 ;
结果:
s_id s_name s_birth s_sex avg(a.s_score)
04 李云 1990-08-06 男 33.3333
06 吴兰 1992-03-01 女 32.5