当前位置:网站首页>数据库实验三:数据查询
数据库实验三:数据查询
2022-06-12 05:43:00 【LEO-max】
实验三 数据查询实验指导
(简单查询和复杂查询)
1.实验目的
(1)对实验一、实验二已建好的student 、course 、sc 表进行查询操作。
(2)充分体会SQL语言的结构化查询功能,让学生充分体会SQL语言的灵活多变,功能强大。
2.实验内容
(1)在实验一和实验二的基础上,进行数据库的查询,充分体会SQL语言的强大功能。简单查询:包含选择和投影的简单单表查询。、包含between、is null等条件的单表查询。包含分组和排序的单表查询、带连接条件的简单多表查询。
(2)嵌套查询 :使用In短语的嵌套查询、使用Exists短语的嵌套查询、使用集合运算的多表查询。
3.实验要求
(1)查询全体学生的学号和姓名。
SELECT sno,sname FROM student;
(2)查询全体学生的详细记录。
SELECT * FROM student;
(3)查询全体学生的姓名和出生年份。
SELECT sname,sage FROM student;
(4)查询选修了课程的学生的学号。
SELECT sno from sc;
(5)查询计算机系的学生的姓名。
SELECT sname from student where sdept='计科系';
(6)查询年龄在20岁以下的计算机系的学生的学号和年龄。
SELECT sno,sage from student where sdept='计科系' AND sage<20;
(7)查询年龄在20—22岁的学生的学号。
SELECT sno FROM student WHERE sage BETWEEN 20 AND 22;
(8)查询信息系、计算机系和外语系的学生的信息。
SELECT * FROM student WHERE sdept IN('计科系','电信系','外语系');
(9)查询姓“吴”的学生的信息。
SELECT * FROM student where sname LIKE '吴%';
(10)查询选修了3号课程的学生的学号及成绩,结果按分数的降序排列。
SELECT sno,grade FROM sc WHERE cno='3' ORDER BY grade DESC;
(11)查询学生总人数。
SELECT COUNT(*) FROM student;
(12)查询选修1号课程的学生的最高分。
SELECT MAX(grade) FROM sc where cno='1';
(13)查询选修了3门以上课程的学生的学号。
SELECT sno FROM sc HAVING COUNT(sno) > 3;
(14)查询每个学生及其选修课程的情况。
SELECT
student.sno,
sname,
course.cno,
course.cname,
grade
FROM
student,
course,
sc
WHERE
student.sno = sc.sno
AND sc.cno = course.cno;
(15)查询选修2号课程且分数在90分以上的所有学生。
SELECT
student.sno,
sname,
grade,
cno
FROM
student,
sc
WHERE
student.sno = sc.sno
AND cno='2'
AND grade>90;
(16)查询每个学生的学号、姓名、选课名及成绩。
SELECT
student.sno,
sname,
cno,
grade
FROM
student,
sc
WHERE
student.sno = sc.sno;
(17) 查询与“张三”在同一系的学生。
SELECT
sno,
sname,
sdept
FROM
student
WHERE
sdept = (
SELECT
sdept
FROM
student
WHERE
sname = '齐俊宝'
);
(18) 查询选修了课程名为“数据库”的学生学号和姓名。
SELECT
student.sno,
sname
FROM
student,
course,
sc
WHERE
student.sno = sc.sno
AND course.cno = sc.cno
AND course.cname = '数据库';
(19) 查询没有选修1号课程的学生的姓名。
SELECT
sname
FROM
student
WHERE
NOT EXISTS (
SELECT
*
FROM
sc
WHERE
student.sno = sc.sno
AND sc.cno = '1'
);
(20) 查询选修了所有课程的学生的姓名。
SELECT
sname
FROM
student
WHERE
NOT EXISTS (
SELECT
*
FROM
course
WHERE
NOT EXISTS (
SELECT
*
FROM
sc
WHERE
student.sno = sc.sno
AND sc.cno = course.cno
)
);
要求写出实验三的全部代码,
注意:
1.全部代码
2.代码的全角半角
3.格式规整,便于批阅
边栏推荐
- Thesis reading_ Figure neural network gin
- C language - how to define arrays
- Stack and queue classic interview questions
- 16. sum of the nearest three numbers
- What is the project advance payment
- Research Report on market supply and demand and strategy of China's digital camera lens industry
- 59 - II. Maximum value of the queue
- Halcon 3D 1 Reading 3D data
- Execute sh script to prompt "[[: not found" solution. The difference between Bash and sh
- SIM卡信号的驱动电流是多少mA,是否是可调节的?
猜你喜欢

Performance test - GTI application service performance monitoring platform

March 23, 2021

POI, easyexcel framework use

网络加速谁更猛?CDN领域再现新王者
![[grpc development] go language builds simple server and client](/img/24/06c3c1219ecad7e117f4df152e9ce7.jpg)
[grpc development] go language builds simple server and client

Available RTMP and RTSP test addresses of the public network (updated in March, 2021)

FPGA语法的细节

Special materials | household appliances, white electricity, kitchen electricity

Introduction to Internet Protocol

beginning一款非常优秀的emlog主题v3.1,支持Emlog Pro
随机推荐
CODIS long link test
什么是工程预付款
Introduction to redis cluster
个人申请OV类型SSL证书
[speech] how to customize ring back tone according to different countries
Execute sh script to prompt "[[: not found" solution. The difference between Bash and sh
Redis cache data consistency and problems
分公司负责人需要承担的法律责任
yolov5
yolov5
Stack and queue classic interview questions
GRP development: four communication modes of GRP
虚函数与纯虚函数的关系
[fastapi] use pycharm to configure and use environment variables for fastapi projects
Matlab: image rotation and interpolation and comparison of MSE before and after
Date ()
Necessary for Test Engineer -- package capturing tool fiddler
Go 接口实现原理【高阶篇】
China's alternative sports equipment market trend report, technology dynamic innovation and market forecast
Go 面向接口编程实战