当前位置:网站首页>SQL Server 2016 学习记录 --- 集合查询
SQL Server 2016 学习记录 --- 集合查询
2022-07-28 10:12:00 【努力的张张】
学习目标:
一、集合查询的相关概念
二、集合查询的几种常用操作
学习内容:
一、集合查询的分类

二、集合查询的几种常用操作
1、并操作
- 形式
<查询块>
union
<查询块>
- 参加union操作的各结果的列数必须相同
- 对应项的数据类型也必须相同
--查询选修了1号课程和2号课程的学生学号
select sno from sc where cno=1
union
select sno from sc where cno=2;

2、交操作与差操作
标准sql中没有提供集合交操作和差操作,但可以用其他方法间接实现
--查询选修了1号课程的学生集合与选修了2号课程的学生集合的交集
select sno from sc
where cno=1 and sno In
(select sno from sc
where cno=2);

--查询计算机科学系的学生与年龄不大于19岁的学生的差集
select * from student
where sdept='CS' and sage>19;

4、对集合操作结果的排序
- order by子句只能用于对最终的查询结果排序,不能对中间结果排序
- 任何情况下,order by 子句只能出现在最后
- 对集合操作结果排序时,order by 子句中可以用数字指定排序属性
--查询计算机科学系的学生与年龄不大于19岁的学生的并集,结果按学号升序排列
select * from student
where sdept='CS'
union
select * from student
where sage<=19
order by sno;

边栏推荐
- Aqua Data Studio 18.5.0导出insert语句
- Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
- 简介
- 6、双指针——递增数组两数之和与目标数相等
- Prometheus 运维工具 Promtool (四)TSDB 功能
- (1)机器学习概念总结
- Step 4 - user development environment settings
- 中兴通讯总裁徐子阳:5nm芯片将在2021年推出
- 语音聊天app——如何规范开发流程?
- 指令系统超全知识点详解
猜你喜欢

MySQL架构原理

Skillfully use NGX_ Lua makes traffic grouping

Voice chat app - how to standardize the development process?

gcc: error trying to exec 'as': execvp: No such file or directory

Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?

11、链表反转

15、判断二维数组中是否存在目标值

什么样的知识付费系统功能,更有利于平台与讲师发展?

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
随机推荐
[cloud based co creation] Huawei cloud: metastudio digital content production line, which seamlessly integrates the virtual world with the real world
Skillfully use NGX_ Lua makes traffic grouping
Vulnerability analysis hevd-0x8.integeroverflow[win7x86]
剑指offer
定了!就在7月30日!
阿里云镜像地址
Huawei takes a 10% stake in fullerene technology, a graphene material manufacturer
15. Judge whether the target value exists in the two-dimensional array
Kubernetes
12. Double pointer -- merge two ordered linked lists
7. Dichotomy -- find a set of repeated or ordered but rotating arrays
巧用ngx_lua做流量分组
️雄关漫道真如铁,而今迈步从头越️
IDEA创建我的第一个项目
Database mysql Foundation
10 minute quick start EVs [play Huawei cloud]
Sleeping barber problem
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
华为入股石墨烯材料厂商富烯科技,持股10%
读写分离备机备份报错