sql语句练习及答案

sql语句练习及答案

ID:31603751

大小:121.02 KB

页数:21页

时间:2019-01-15

sql语句练习及答案_第1页
sql语句练习及答案_第2页
sql语句练习及答案_第3页
sql语句练习及答案_第4页
sql语句练习及答案_第5页
资源描述:

《sql语句练习及答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、sql语句练习题1数据库有如下四个表格:student(sno,sname,sage,ssex,sdpt)学生表系表(dptno,dname)course(cno,cname,gradet,tno)课程表sc(sno,cno,score)成绩表teacher(tno,tname)教师表要求:完成以下操作1.查询姓"欧阳"且全名为三个汉字的学生的姓名。select sname from student where sname like “欧阳__‟;2.查询名字中第2个字为"阳"字的学生的姓名和学号。 select sname,sno from student

2、 where sname like '_阳%';3.查询所有不姓刘的学生姓名。select sname,sno,ssex from student where sname not like “刘%”;4.查询db_design课程的课程号和学分。 select cno,ccreditfrom course where cname like 'db_design' 5.查询以"db_"开头,且倒数第3个字符为i的课程的详细情况。 select * from course where cname like 'db%i_ _';6.某些学生选修课程后没有参加考试,

3、所以有选课记录,但没有考试成绩。查询缺少成绩的学生的学号和相应的课程号。select sno,cno from sc where grade is null;1.查所有有成绩的学生学号和课程号。select sno,cno from sc where grade is not null;2.查询计算机系年龄在20岁以下的学生姓名。 select sname from student where sdept= 'cs' and sage<20;3.查询选修了3号课程的学生的学号及其成绩,查询结果按分数降序排列。 select sno,grade from sc

4、 where cno= ' 3 ' order by grade desc;4.查询学生总人数。select count(*) from student;5.查询选修了课程的学生人数。select count(distinct sno) from sc;6.计算1号课程的学生平均成绩。select avg(grade) from sc where cno= ' 1 ';7.查询选修1号课程的学生最高分数。select max(grade) from sc where cno= ' 1 ';8.查询学生200215012选修课程的总学分数。select sum

5、(grade) from sc,course wheresno= ' 200215012 ' and sc.cno=course.cno;1.查询选修了3门以上课程的学生学号。select sno from sc group by sno having count(*) >3; 2.查询每个学生及其选修课程的情况。selectstudent.*,sc.*,course.*fromstudent,sc,coursewherestudent.sno=sc.snoandsc.cno=course.cno;3.查询每个学生及其选修课程的情况包括没有选修课程的学生4.

6、查询选修2号课程且成绩在90分以上的所有学生的学号、姓名selectstudent.sno,student.snamefromstudent,scwherestudent.sno=sc.snoandsc.cno=”2‟andsc.grade>90;5.查询每个学生的学号、姓名、选修的课程名及成绩。selectstudent.sno,sname,ssex,sage,sdept,cno,gradefromstudentleftoutjoinscoon(student.sno=sc.sno);6.查询与“刘晨”在同一个系学习的学生。selectsno,sname,

7、sdeptfromstudentwheresdeptin(selectsdeptfromstudentwheresname=”刘晨‟);7.查询选修了课程名为“信息系统”的学生学号和姓名selectsno,snamefromstudentwheresnoin(selectsnofromscwherecnoin(selectcnofromcoursewherecname=”信息系统‟));1.找出每个学生超过他选修课程平均成绩的课程号。selectsno,cnofromscxwheregrade>=(selectavg(grade)fromscywherey.

8、sno=x.sno);2.将一个新学生记录(学号:2

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。