当前位置:网站首页>Mysql数据库轻松学09—数据分析师常用:数据查询语言DQL之多表查询
Mysql数据库轻松学09—数据分析师常用:数据查询语言DQL之多表查询
2022-06-22 01:34:00 【潇洒白羊】
1 表之间的关系
1.1 一对一

1.2 一对多

1.3 多对多

2 连接方式
2.1 横向连接
2.1.1 内连接 inner join
按照连接条件连接两个表,返回满足条件的行
select 字段1[,…] from 表1[ inner] join 表2 on 连接条件;
2.1.2 左连接 left join
结果中除了包括满足连接条件的行外,还包括左表的所有行
select 字段1[,…] from 表1 left join 表2 on 连接条件;
2.1.3 右连接 right join
结果中除了包括满足连接条件的行外,还包括右表的所有行
select 字段1[,…] from 表1 right join 表2 on 连接条件;
2.1.4 笛卡尔积 cross join
假设集合A={a,b},集合B={1,2,3},则两个集合的笛卡尔积为{(a,1),(a,2),(a,3),(b,1),(b,2),(b,3)}
select 字段1[,…] from 表1,表2[,…];
select 字段1[,…] from 表1 cross join 表2[,…];
消除笛卡尔积:
逐行判断,相等的留下,不相等的排除
select 字段1[,…] from 表1,表2[,…] where 筛选条件;
2.1.5 自连接
通过设置表别名,将同一张表虚拟为多张表进行连接
select * from tabel a inner join table b
on a.id = b.id
2.2 纵向连接
2.2.1 概念
把多条select语句的查询结果合并为一个结果集
被合并的结果集的列数、顺序和数据类型必须完全一致
2.2.2 union去重:
#select 字段1[,字段2,…] from 表名 union select 字段1[,字段2,…] from 表名;
select * from t1 union select * from t2;
2.2.3 union all不去重:
#select 字段1[,字段2,…] from 表名 union all select 字段1[,字段2,…] from 表名;
select * from t1 union all select * from t2;
3 连接条件
3.1 等值连接
表1.id=表2.id
3.2 不等值连接
表1.id 比较 表2.id
边栏推荐
- 防关联浏览器原理及对策
- acwing 837. 连通块中点的数量 (并查集维护额外信息---集合数量)
- shadertoy 实现简易指南针
- 数字信号处理
- 第 12 章 基于块匹配的全景图像拼接--Matlab深度学习实战图像处理应用
- Mathematical knowledge in the first round of noip preliminary round csp-j1 csp-s1 Sinorgchem (III)
- Recommended by Ali, Tencent and Baidu software testing engineers - waterfall model of software testing model
- 英特尔发展史概述
- NOIP初赛 CSP-J1 CSP-S1 第1轮 初赛 信奥中的数学知识(三)
- Expenditure budget and adjustment records and use records output use progress construction process records
猜你喜欢

BSV上的委托合约

acwing 838. 堆排序 (手写一个堆)

Shardingsphere-proxy-5.0.0 implementation of distributed hash modulo fragmentation (4)

机器学习编译第1讲:机器学习编译概述

【第 07 章 基于主成分分析的人脸二维码识别MATLAB深度学习实战案例】

Machine learning pytoch implementation case LSTM case (flight number prediction)

LeetCode+ 46 - 50

求一个防关联检测工具,浏览器指纹在线检测

出现UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe9 in position 0: ordinal not in range解决方法

The Sandbox 与《时代周刊》达成合作,在元宇宙建立“纽约时报广场”
随机推荐
GAMES-101-个人总结归纳-Transformation
acwing 838. Heap sort (write a heap)
MBA-day24 最值问题
阿里,腾讯,百度软件测试工程师推荐——软件测试模型之瀑布模型
Mathematical knowledge in the first round of noip preliminary round csp-j1 csp-s1 Xinjiang Olympic Games (II)
ASEMI肖特基二极管1N5819参数,1N5819代换,1N5819货源
The Sandbox 与《时代周刊》达成合作,在元宇宙建立“纽约时报广场”
Heidisql always makes errors when inserting data. What should I do
DAST black box vulnerability scanner part 4: scanning performance
DAST 黑盒漏洞扫描器 第四篇:扫描性能
如何获取自由和财富
【第 20 章 基于帧间差法进行视频目标检测--MATLAB软件深度学习应用】
2022年Q1手机银行用户规模达6.5亿,加强ESG个人金融产品创新
Preliminary competition of noip improvement group III. problem solving exercise set noip1995-noip2018
英伟达笔试面试题整理DIY
测试apk-异常管控Sensor攻击者开发
第298场力扣周赛个人题解
【第 17 章 基于 Harris 的角点特征检测--Matlab机器学习项目实战】
twenty-one
谁会用pyspark将筛选过后本地数据上传到spark sql