使用 T-SQL 语句完成数据综合检索
内容:
1. select 语句的基本语法格式和执行方法;
2. 连接查询的表示及使用;
3. 嵌套查询的表示及使用;
4. 集合查询的表示及使用;
以实验三数据为基础,用 T-SQL 语句实现下列数据查询操作。
- 查询选修了“数据库”的学生的基本信息,结果列显示学号,姓名,性别,院系。
select snum,sname,ssex,sdept from student
where snum in (select sno from cjwhere cno=(select cnum from course where cname='数据库'))
- 查询年龄比“李勇”小的学生的学号、课程号、成绩。
select sno,cno,score from cj
where sno in (select snum from studentwhere sage<(select sage from student where sname='李咏'))
- 查询其他系中比院系为“信息系”的学生中年龄最小者要大的学生的信息。
select * from student
where sdept not like '信息系' and sage>(select min(sage) from studentwhere sdept='信息系')
- 查询其他系中比院系为“商务系”的学生年龄都大的学生的姓名。
select sname from student
where sdept not like '商务系' and sage>(select max(sage) from studentwhere sdept='商务系')
- 查询“c001”课程的成绩高于 70 的学生姓名。
select distinct student.sname from cj,student
where student.snum=cj.sno and cj.cno='c001' and cj.score>70
- 查询没有选修的学生姓名。
select sname from student
where snum not in (select sno from cj)
- 查询学校开设的课程总数。
select COUNT(cnum) from course
- 查询选修两门及两门以上课程的学生姓名。
select student.sname from student,cj
where student.snum=cj.sno
group by student.sname,cj.sno having count(cj.cno)>1
- 查询以“数据”开头的课程的详细情况;
select * from course
where cname like '数据%'
- .查询名字中第 2 个字为“向”的学生姓名和学号及选修的课程号、课程名;
select cnum,cname from course
where exists(select * from cj where exists(select * from student where course.cnum=cj.cno and sname like '_向%'))
- 列出选修了“数据库”或者“数学”的学生学号、姓名、所在院系、选修课程号及成绩;
select student.snum,student.sname,student.sdept from student,cj
where student.snum=cj.sno and cno in (select cnum from course where cname='数据库' or cname='数学')
- 查询缺少成绩的所有学生的详细情况;
select distinct * from student
where snum not in(select distinct sno from cj)
- 查询与‘张力’(假设姓名唯一)年龄不同的所有学生的信息;
select * from student
where sage<>(select sage from studentwhere sname like '张力')
- 查询所选课程的平均成绩大于张力的平均成绩的学生学号、姓名及平均成绩;
select snum,sname,AVG(score)as '平均成绩' from student,cj
where student.snum=cj.sno
group by student.snum,sname having AVG(score)>(select AVG(score) from cj,student
where student.snum=cj.sno and student.sname= '张力')
- 使用嵌套查询列出选修了“数据结构”课程的学生学号和姓名;
select snum,sname from student
where snum in(select sno from cj where cno in (select cnum from course where cname='数据结构'))
- 使用嵌套查询查询其它系中年龄小于“计算机系”的某个学生的学生姓名、年龄和院系;
select sname,sage,sdept from student
where sdept not like '计算机系' and sage<(select MIN(sage) from student)
- .列出与‘张力’在一个院系的学生的信息;
select * from student
where sdept=(select sdept from student where sname='张力') and sname<>'张力'
使用 T-SQL 语句完成数据综合检索相关推荐
- JavaWeb学习笔记(数据库、SQL语句、数据查询语法、完整性约束、编码、备份和恢复数据、多表查询)
数据库.SQL语句.数据查询语法.完整性约束.编码.备份和恢复数据.多表查询 JavaWeb学习笔记 数据库 数据库概念 基本命令 启动和关闭mysql服务器 客户端登录退出mysql SQL语句 S ...
- 使用SQL语句UPDATE数据,怎样知道是否UPDATE成功
http://www.ixpub.net/thread-1252609-1-1.html 使用SQL语句UPDATE数据,怎样知道是否UPDATE成功 如题,我在RPG中使用SQL语句UPDATE数据 ...
- 利用SQL语句对数据进行操作:插入、更新与删除数据行
My目录 前言 一.T-SQL的组成 二.插入数据行 1.一次插入一行数据 2.一次插入多行数据 三.更新数据行 四.删除数据行 前言 结构化查询语言(Structured Query Languag ...
- mysql中常用的筛查语句,使用SQL语句进行数据筛选的方法
在使用VBA对数据库进行访问时,利用SQL语句能够方便地实现对数据库的查询.本文使用SQL语句实现多条件查询,使用Select语句从"成绩管理.accdb"数据库文件中获取1班中数 ...
- 使用SQL语句删除数据表
使用SQL语句删除数据表 其语法格式如下: database_name:要在其中创建表的数据库名称. schema_name:表所属架构的名称. table_name:要删除的表名称. DROP TA ...
- 异构数据库之间完全可以用SQL语句导数据 ths 碧血剑!
问题:异构数据库之间完全可以用SQL语句导数据.大家抛弃BatchMove吧 如果觉得好请Up一下,如果觉得不好也请Up一下 ( 积分:1, 回复:684, 阅读:43158 ) 分类:数据库-C/S ...
- 使用SQL语句创建数据表(SQL Server)
数据库 表的创建(SQL Server) 文章目录 数据库 表的创建(SQL Server) 使用SQL语句创建数据表 使用SQL语句创建数据表 CREATE TABLE的语法格式如下 databas ...
- 数据库学习day_02:表格相关sql语句 / 表格数据相关sql语句 / sql中的数据类型 / 导入外部sql文件 / 去重.是否为null.and与or.in.[x,y]
1.表相关的SQL语句 操作表相关的SQL 必须先使用某个数据库 create database mydb1; show create database mydb1; use mydb1; 如果默认不 ...
- SQL语句的强大综合集锦
--语 句 功 能 --数据操作 SELECT --从数据库表中检索数据行和列 INSERT --向数据库表添加新数据 ...
最新文章
- atca背板_ATCA介绍全解.ppt
- Luogu P1407 [国家集训队]稳定婚姻 (二分图写法)
- 属性getter和setter
- html图片自动剪裁,HTML canvas图像裁剪
- keyerror什么意思python_为什么会出现keyerror?
- 【不读唐诗,不足以知盛世】盛唐诗坛的璀璨明星们
- 正在配置更新请勿关闭计算机怎么办,电脑开机“显示正在配置更新请勿关闭计算机”该怎么办?...
- android viewholder继承,Android RecyclerView中的ViewHolder
- m3u8在线播放接口附成品
- 云通信-腾讯云,TLS独立模式公私钥生成
- MySQL教程 你想要的几乎都有
- 认知智能三大技术体系之类脑模型简介
- Vue+bpmn.js自定义流程图之palette(二)
- linux 下查看机器配置命令
- 禅道项目改掉头部公司名
- 联盟里这么多企业,哪一家会是我的东家?
- 为何魅族智能家居生态圈更值得期待
- ICN6202是一颗MIPI DSI转LVDS的桥接芯片
- 考研复试自我介绍总结
- oracle数据库scn是什么
热门文章
- xfs文件系统恢复工具xfs_undelete
- el-table表格操作列合并行
- openstack冷迁移/Resize源码分析(二)
- 阿里云服务器到期会提醒吗
- Hive性能优化(全面)解决数据倾斜等问题
- ::ZheTian / 遮天 强大的Anti-Virus对抗工具
- html5播放器播放尺寸出界了,尺寸规范
- 东方证券首席架构师樊建:企业微服务架构转型实践
- Python爬虫示例:爬取 13 个旅游城市,看看大家放假了都爱去哪玩
- 手动绘制R语言Logistic回归模型的外部验证校准曲线(Calibration curve)(2)