admin 管理员组

文章数量: 1087652


2024年4月17日发(作者:vuejs常用的事件修饰符)

word格式-可编辑-感谢下载支持

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 where sname like '_阳%';

3. 查询所有不姓刘的学生姓名。

select sname,sno,ssex

from student

where sname not like “刘%”;

4. 查询db_design课程的课程号和学分。

select cno,ccredit from course

where cname like 'db_design'

5. 查询以"db_"开头,且倒数第3个字符为i的课程的详细情况。

select * from course where cname like 'db%i_ _';

6. 某些学生选修课程后没有参加考试,所以有选课记录,但没有考试成绩。查询缺少成绩

的学生的学号和相应的课程号。

select sno,cno from sc where grade is null;

word格式-可编辑-感谢下载支持

7. 查所有有成绩的学生学号和课程号。

select sno,cno from sc where grade is not null;

8. 查询计算机系年龄在20岁以下的学生姓名。

select sname from student where sdept= 'cs' and sage<20;

9. 查询选修了3号课程的学生的学号及其成绩,查询结果按分数降序排列。

select sno,grade from sc where cno= ' 3 ' order by grade

10. 查询学生总人数。

select count(*) from student;

11. 查询选修了课程的学生人数。

select count(distinct sno) from sc;

12. 计算1号课程的学生平均成绩。

select avg(grade) from sc where cno= ' 1 ';

13. 查询选修1号课程的学生最高分数。

select max(grade) from sc where cno= ' 1 ';

14. 查询学生200215012选修课程的总学分数。

select sum(grade) from sc,course

where sno= ' 200215012 ' and =;

15. 查询选修了3门以上课程的学生学号。

select sno from sc group by sno having count(*) >3;

16. 查询每个学生及其选修课程的情况。

desc;


本文标签: 课程 学生 查询 选修 编辑