数据库--简单查询
简单查询
简单查询要求如下:
(1)查询全体学生的学号和姓名。
(2)查询全体学生的姓名和出生年份。
(3)显示student表中的所有行和列。
(4)学分为2的课程名。
(5)查询名族为汉族的学生姓名和年龄。
(6)查询考试成绩中有不及格科目的学生的学号。
(7)查询年龄在18-20岁(包括18岁和20岁)之间的学生的姓名和年龄。
(8)查询所有女学生的姓名和出生年份。
(9)查询通信系和计算机系学生的姓名和性别。
(10)查询既不是通信系也不是计算机系的学生的姓名和性别。
(11)查询所有姓张的学生的姓名、学号和性别。
(12)查询全名为两个汉字的学生的姓名。
(13)查询所有不姓张的学生的姓名。
(14)查询名字中第2个字为“无”字的学生的姓名和学号。
(15)查询缺考学生的学号和课程号。
(16)查询所有有成绩的学生的学号和课程号。
(17)查询选修了课程的学生的学号并去除重复行。
提供表格信息如下:
student表
|
sno |
sname |
ssex |
sage |
snat |
sdept |
|
S1 |
赵无言 |
男 |
18 |
汉族 |
计算机系 |
|
S2 |
蒋洪 |
男 |
19 |
回族 |
通信系 |
|
S3 |
汪艳 |
女 |
18 |
汉族 |
自动化 |
|
S4 |
张拟 |
女 |
18 |
汉族 |
通信系 |
|
S5 |
孙瑶 |
男 |
19 |
汉族 |
电子系 |
|
S6 |
张军军 |
男 |
20 |
回族 |
计算机系 |
course表
|
cno |
cname |
credit |
|
001 |
C语言程序设计 |
2 |
|
002 |
高数 |
3 |
|
003 |
大学英语 |
2 |
|
004 |
计算机网络 |
3 |
|
005 |
数据库原理 |
2 |
sc表
|
sno |
cno |
grade |
|
S1 |
001 |
80 |
|
S1 |
003 |
75 |
|
S2 |
002 |
54 |
主要运行代码如下:
create database JXGL1
on
(name=JXGL,
filename='D:\sql\JXGL1.mdf',//选择自己的文件保存位置
size=10MB,
maxsize=30MB,
filegrowth=5MB)
log on
(name=xxgl_log,
filename='D:\sql\JXGL1_log.ldf',
size=4MB,
maxsize=10MB,
filegrowth=2MB)
use JXGL1
go
create table S(sno char(12)primary key,
sname char(10),
sex char(2),
age tinyint,
sdept nchar(20)
)
create table C
(cno char(3)primary key,
cname nchar(20),
Tname varchar(20),
credit tinyint
)
create table SC
(sno char(12)references S(sno),
cno char(3)references C(cno),
grade float,
primary key(sno,cno),
)
insert into S values
('S1','程晓晴','女',21,'CS'),
('S2','吴玉江','男',20,'CS'),
('S3','姜云','女',18,'CS'),
('S4','张峰','男',19,'CS'),
('S5','张丽丽','女',21,'MA'),
('S6','李文','女',25,'MA'),
('S7','李文远','女',19,'MA'),
('S8','张峰名','男',20,'IS'),
('S9','王大力','男',21,'IS'),
('S10','张姗姗','女',22,'IS')
insert into c values
('C1','C语言程序设计','殷老师',4),
('C2','计算机网络','王老师',4),
('C3','数据结构','詹老师',4),
('C4','数据库系统','詹老师',3),
('C5','Jave Web','支老师',3)
insert into SC values
('S1','C1',96),
('S1','C2',55),
('S1','C3',84),
('S1','C5',52),
('S2','C1',84),
('S2','C2',90),
('S2','C4',85),
('S3','C5',73),
('S3','C4',Null),
('S4','C1',50)
use JXGL1
select sno,sname
from S
SELECT SNAME,AGE
FROM S
SELECT * FROM S
select cname
from C
where credit=3
select sname,age
from S
where sno='s1'
select distinct sno
from sc
where grade<60
select sname,age
from S
where age between 18 and 20
select sname
from s
where sex='女'
select sname,sex
from s
where sdept in ('Is','cs')
select sname,sex
from S
where sdept not in('is','cs')
select sname,sno,sex
from s
where sname like '张%'
select sname
from s
where sname like '__'
select sname
from S
where sname not like '张%'
select sname,sno
from S
where sname like '_文%'
select sno,cno
from sc
where grade is null
select sno,cno
from sc
where grade is not null
select sno
from SC
where grade is not null
group by sno
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐

所有评论(0)