实验目的:
- 学生表Student,由学号(Sno)、姓名(Sname)、性别(Ssex)、年龄(Sage)、所在系(Sdept)五个属性组成,记作:
Student(Sno,Sname,Ssex,Sage,Sdept)
其中主码为Sno。姓名取值唯一,性别取值为男或女,默认为男。
Student
Sno | Sname | Sage | Ssex | Sdept |
---|---|---|---|---|
98001 | 钱横 | 18 | 男 | CS |
98002 | 王林 | 19 | 女 | CS |
98003 | 李民 | 20 | 男 | IS |
98004 | 赵三 | 16 | 女 | MA |
98005 | 欧阳勇 | 19 | 男 | MA |
98019 | 李四 | 18 | 男 | IS |
- 课程表Course,由课程号(Cno)、课程名(Cname)、先修课号(Cpno)、学分(Ccredit)四个属性组成,记作:
Course(Cno,Cname,Cpno,Ccredit)
其中主码为Cno。Cname取值唯一
Course
Cno | Cname | Cpno | Ccredit |
---|---|---|---|
1 | 数据库系统 | 5 | 4 |
2 | 数学分析 | NULL | 2 |
3 | 信息系统导论 | 1 | 3 |
4 | 操作系统原理 | 6 | 3 |
5 | 数据结构 | 7 | 4 |
6 | 数据处理基础 | NULL | 4 |
7 | C语言 | 6 | 3 |
- 学生SC,由学号(Sno)、课程号(Cno)、成绩(Grade)三个属性组成,记作:
SC(Sno,Cno,Grade)
其中主码为(SNO,CNO),sno参照student表的sno列,cno参照course表的cno列。grade取值范围0-100。
Sc
Sno | Cno | Grade |
---|---|---|
98001 | 1 | 87 |
98001 | 2 | 67 |
98001 | 3 | 90 |
98002 | 2 | 95 |
98002 | 3 | 88 |
98004 | 2 | Null |
对JXGL数据库进行查询。
查询全体学生的学号与姓名。
select sno,sname from student
查询全体学生的姓名、学号、所在系。
select sname,sno,sdept from student
查询全体学生的详细记录。
select * from student
查全体学生的姓名及其出生年份。
select sname,year(getdate())-sage as '出生年份' from student
查询全体学生的姓名、出生年份和所在系,要求用小写字母表示所有系名。
select sname,year(getdate())-sage as '出生年份',lower(sdept) 'sdept' from student
查询选修了课程的学生学号。
select distinct sno from sc
查询所有年龄在20岁以下的学生姓名及其年龄。
select sname,sage from student where sage<20
查询年龄在20~23岁(包括20岁和23岁)之间的学生的姓名、系别和年龄。
Select sname,sdept,sage From student Where sage between 20 and 23
查询年龄不在20~23岁之间的学生姓名、系别和年龄。
Select sname,sdept,sage From student Where sage not between 20 and 23
查询信息系(IS)、数学系(MA)和计算机科学系(CS)学生的姓名和性别。
Select sname,ssex From student Where sdept in('IS','MA','CS')
查询既不是信息系、数学系,也不是计算机科学系的学生的姓名和性别。
Select sname,ssex From student Where sdept not in('IS','MA','CS')
查询学号为98001的学生的详细情况。
Select * From student Where sno='98001'
查考试成绩大于等于90的学生的学号。
Select sno From sc Where grade>=90
查询所有姓刘学生的姓名、学号和性别。
Select sname,sno,ssex From student Where sname like '刘%'
查询姓”欧阳”且全名为三个汉字的学生的姓名。
Select sname From student Where sname like '欧阳_'
查询名字中第2个字为”阳”字的学生的姓名和学号。
Select sname,sno From student Where sname like '_阳%'
查询所有不姓刘的学生姓名。
Select sname,sno,ssex From student Where sname not like '刘%'
某些学生选修课程后没有参加考试,所以有选课记录,但没有考试成绩。查询缺少成绩的学生的学号和相应的课程号。
Select sno,cno From sc Where grade is null
查所有有成绩的学生学号和课程号。
Select sno,cno From sc Where grade is not null