select
s.*,c.cname,t.tname,sc.score
from
t_mysql_teacher t,
t_mysql_course c,
t_mysql_student s,
t_mysql_score sc
where
t.tid=c.cid
and c.cid=sc.cid
and sc.sid=s.sid
and t.tname= '张三';
10)查询没有学全所有课程的同学的信息
select s.sid,s.sname,count(sc.score) n from
t_mysql_student s
left join
t_mysql_score sc
on s.sid=sc.sid
group by s.sid,s.sname
having n<
(select count(1) from t_mysql_course);
11)查询没学过"张三"老师讲授的任一门课程的学生姓名
select
s.sid,s.sname
from
t_mysql_score sc,
t_mysql_student s
where s.sid =sc.sid and sc.cid
not in
(select cid from
t_mysql_course c,
t_mysql_teacher t
where c.tid=t.tid and t.tname='张三')
group by
s.sid,s.sname;
12)查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩
select
s.sid,
s.sname,
avg(sc.score) n
from
t_mysql_student s,
t_mysql_score sc
where s.sid = sc.sid and sc.score<60
group by s.sid,s.sname;
13)检索" 01 "课程分数小于 60,按分数降序排列的学生信息
select
s.*,
sc.score
from
t_mysql_student s,
t_mysql_score sc
where s.sid=sc.sid and sc.cid='01' and sc.score<60
order by sc.score desc;
14)按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩
select
s.sid,
s.sname,
sum((case when sc.cid='01' then sc.score end)) 语文,
sum((case when sc.cid='02' then sc.score end)) 数学,
sum((case when sc.cid='03' then sc.score end)) 英语,
round(avg(sc.score),2) 平均分数
from
t_mysql_score sc
right join
t_mysql_student s on sc.sid=s.sid
group by
s.sid,
s.sname;
select
c.cid,c.cname,
max(sc.score) 最高分,
min(sc.score) 最低分,
count(sc.sid) 人数,
round(avg(sc.score),2) 平均分,
concat(round(sum(if(sc.score>=60,1,0))/
(select count(*) from t_mysql_student)*100,2),'%') 及格率,
concat(round(sum(if(sc.score>=70 and score<=80,1,0))/
(select count(*) from t_mysql_student)*100,2),'%') 中等率,
concat(round(sum(if(sc.score>=80 and score<=90,1,0))/
(select count(*) from t_mysql_student)*100,2),'%') 优良率,
concat(round(sum(if(sc.score>=90,1,0))/
(select count(*) from t_mysql_student)*100,2),'%') 优秀率
from
t_mysql_score sc
left join
t_mysql_course c on sc.cid=c.cid
group by
c.cid,c.cname