1.查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数 select *from (select *from sc where sc.cid='01') as a inner join(select *from sc where sc.cid='02') as b on a.sid=b.sid where a.score>b.score;2.查询同时存在" 01 "课程和" 02 "课程的情况 select* from (select *from sc where sc.cid='01') as a inner join (select *from sc where sc.cid='02') as b on a.sid=b.sid;3.查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null ) select* from (select *from sc where sc.cid='01') as a left outer join (select *from sc where sc.cid='02') as b on a.sid=b.sid;4.查询平均成绩大于等于 60 分的同学的学生编号和学生姓名和平均成绩 5.查询在 SC 表存在成绩的学生信息 select s.* from student as s inner join (select distinct sid from sc) as a on s.sid=a.sid;6.查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩(没成绩的显示为null) 7.查询「李」姓老师的数量select count(*) from teacher where tname like '李%'; 8.查询学过「张三」老师授课的同学的信息 -- 同时连接多张表: select student.*from teacher  ,course  ,student, scwhere teacher.Tname='张三'and   teacher.TId=course.TIdand   course.CId=sc.CIdand   sc.SId=student.SId9.查询没有学全所有课程的同学的信息 10.查询没学过"张三"老师讲授的任一门课程的学生姓名 11.检索" 01 "课程分数小于60,按分数降序排列的学生信息 select student.* from student,(select sid from sc where cid=01 and score<60 order by score desc) as a where student.sid=a.sid;12.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩 13.按各科成绩进行排序,并显示排名,Score 重复时保留名次空缺 14.按各科成绩进行排序,并显示排名, Score 重复时合并名次 15.查询学生的总成绩,并进行排名,总分重复时保留名次空缺 16.查询学生的总成绩,并进行排名,总分重复时不保留名次空缺 17.统计各科成绩各分数段人数:课程编号,课程名称,[100-85],[85-70],[70-60],[60-0] 及所占百分比 18.查询各科成绩前三名的记录 19.查询每门课程被选修的学生数 select cid,count(sid) as count_sid from sc group by cid; 20.查询出只选修两门课程的学生学号和姓名 select sc.sid,student.sname from sc,student where sc.sid=student.sid group by sc.sid having count(cid)=2;  21.查询男生、女生人数 select ssex,count(ssex)from student group by ssex; 22.查询名字中含有「风」字的学生信息 select *from student where sname like ***%'; 23.查询同名同姓学生名单,并统计同名人数 select * from student group by sname having count(sname)>=2; 24.查询 1990 年出生的学生名单 select *from student where sage like '1990%'; 25.查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列 select sc.cid,avg(score) as avg_score from sc group by sc.cid order by avg_score desc,cid; 26.查询平均成绩大于等于 85 的所有学生的学号、姓名和平均成绩 select sc.sid,student.sname,avg(sc.score) as avg_score from sc,student where sc.sid=student.sid group by sid having avg_score>=85; 27.查询课程名称为「数学」,且分数低于 60 的学生姓名和分数 28.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况) select s.*,sc.score from student as s left outer join sc on s.sid=sc.sid; 29.查询任何一门课程成绩在 70 分以上的姓名、课程名称和分数 30.查询不及格的课程
点赞 0
评论 0
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务