• 数据库练习题


    写在前面

            这篇文章是一些关于数据库的练习题,所用的数据库为学生课程数据库,其中有三张表分别为学生表(student)、课程表(course)、成绩表(sc)。学生表有6列,分别为学号(sno)、姓名(sname)、性别(ssex)、年龄(sage)、所在系(sdept)、高考分数(gkfs)。课程表有5列,分别为课程号(cno)、课程名(cname)、先行课的课程号(cpno)、学分(credit)、授课教师(teacher)。成绩表有3列,分别为学号(sno)、课程号(cno)、成绩(grade)。

    答案仅供参考,如有错误请指出


    1.查询全体学生的学号、性别。

    1. select sno,ssex
    2. from student

    2.查询女性学生的学号、姓名和所在系。

    1. select sno,sname,sdept
    2. from student
    3. where ssex like '女';

    3.查询选修了课程的学生学号,并且学号不重复。

    1. select distinct sno
    2. from sc;
    3. select sno
    4. from sc
    5. group by sno;

    4.查询选修了1001号课程成绩在70分以上,或者选修了1003号课程的学生的学号和成绩。

    1. select sno,grade
    2. from sc
    3. where (cno like '1001' and grade >= 70) or (cno = 1003);

    5.查询1002 号课程的成绩表,按学号升序排列。

    1. select sno,grade
    2. from sc
    3. where cno = 1002
    4. order by sno ASC;

    6.查询年龄在19岁以上学生的学号、姓名、性别和年龄。

    1. select sno,sname,ssex,sage
    2. from student
    3. where sage >= 19;

    7. 查询学生选修课程成绩在60分及以上的学生的学号和成绩。

    1. select sno,grade
    2. from sc
    3. where grade >= 60;

    8.查询市场营销系全部学生的学号和姓名。

    9. 查询全体学生的学号、姓名、年龄(起别名:age)。

    1. select sno,sname,sage age
    2. from student;

    10. 查询‘计算机科学’系和‘信息管理’系学生的学号、姓名和性别。

    1. select sno,sname,ssex
    2. from student
    3. where sdept in ('计算机科学','信息管理');

    11. 查询年龄不在18~20岁之间的学生的姓名、年龄和系名。

    1. select sname,sage,sdept
    2. from student
    3. where sage not between 18 and 20;

    12. 查询选修课程超过 1 门的学生学号及选课门数(别名quantity)。

    1. select sno,count(cno) quantity
    2. from sc
    3. group by sno
    4. having count(*) > 1;

    13. 查询信息管理系年龄在18岁以上的学生的姓名和性别。

    1. select sname,ssex
    2. from student
    3. where sdept like '信息管理' and sage >= 18;

    14. 查询名字中含有‘军’的学生的学号、姓名和性别。

    1. select sno,sname,ssex
    2. from student
    3. where sname like '%军%';

    15. 查询全体课程的课程号。

    1. select cno
    2. from course
    3. group by cno;

    16.查询所有学生的sname、cname、grade列。

    1. select sname,cname,grade
    2. from student,course,sc
    3. where student.sno = sc.sno and sc.cno = course.cno;

    17.按分数降序排序,输出信息系学生中选修了“数据库”课程的学生的姓名和分数。

    1. select sname,grade
    2. from student,sc
    3. where student.sno = sc.sno and sdept like '信息' and sc.cno = 1001
    4. order by grade DESC;

    18.检索学号为2008036406号学生所学课程的课程名与任课教师。

    1. select cname,teacher
    2. from sc,course
    3. where sc.sno like '2008036406' and sc.cno = course.cno;

    19.查询其它系中比信息系某一学生年龄大的学生姓名和年龄。

    1. select sname,sage
    2. from student
    3. where sage > any(
    4. select sage
    5. from student
    6. where sdept = '信息') and sdept <> '信息';

    20.查询每个学生的情况(包括学号、姓名、性别、系别)和他选修的课程名和成绩。

    1. select student.sno,sname,ssex,sdept,cname,grade
    2. from student,course,sc
    3. where student.sno = sc.sno and sc.cno = course.cno;

    21.求选修1001号课程且成绩为90分以上的学生的学号、姓名及成绩。

    1. select student.sno,sname,grade
    2. from student,sc
    3. where student.sno = sc.sno and sc.cno = '1001' and sc.grade >= 90;

    22.查询每一门课的间接先修课。

    1. select first.cname,second.cname cpname
    2. from course first,course second
    3. where first.cpno = second.cno;

    23.求选修了高等数学课(课程号为1002)的学生学号和成绩,并要求对查询结果按成绩降序排列,如果成绩相同则按学号升序排列。

    1. select sno,grade
    2. from sc
    3. where cno = '1002'
    4. order by grade DESC,sno ASC;

    24.求选修高等数学课其且成绩在80-90之间的学生学号和成绩,并将成绩乘以系数0.8输出(起别名Grade)。

    1. select sno,grade*0.8 Grade
    2. from sc
    3. where cno = '1002' and grade between 80 and 90;

    25.求学生的学号、姓名、选修的课程名及成绩。

    1. select student.sno,sname,cname,grade
    2. from student,sc,course
    3. where student.sno = sc.sno and sc.cno = course.cno;

    26.查询选修1003号课程且成绩在85分以上的所有学生的姓名。

    1. select sname
    2. from student,sc
    3. where student.sno = sc.sno and cno = '1003' and grade >= 85;

    27.查询先行课的学分为4的课程号和课程名。

    1. select first.cno,first.cname
    2. from course first,course second
    3. where first.cpno = second.cno and second.credit = 4;

    28.查询选修 1001 号课程的男同学的学号、姓名和成绩。

    1. select student.sno,sname,grade
    2. from student,sc
    3. where student.sno = sc.sno and sc.cno = 1001 and ssex = '男';
  • 相关阅读:
    Linux环境基础开发工具
    查看进程占用端口及杀死进程命令
    wls2 ubuntu conda出现诡异ssl错误
    docker&kubernets篇(二十二)
    机器学习-搜索技术:从技术发展到应用实战的全面指南
    CrossOver22全新版功能简介 免费mac虚拟机工具
    深入剖析计算机网络和操作系统:面试必备知识解析
    SPI 串行外围设备接口
    你不知道的Spring的依赖的查找和注入的来源
    皕杰报表中填报控件显示模式控制问题
  • 原文地址:https://blog.csdn.net/m0_52660785/article/details/127545202