sql横着连接起来sql_SQL联接的简要介绍(到目前为止)

sql横着连接起来sql

SQL Join是什么意思? (What does a SQL Join mean?)

A SQL join describes the process of merging rows in two different tables or files together.

SQL连接描述了将两个不同表或文件中的行合并在一起的过程。

Rows of data are combined based on values in a selected column.

根据选定列中的值组合数据行。

In the example above, this is the Item column.

在上面的示例中,这是“ 项目”列。

An Item, Apple, has both a price and a quantity, but in different tables.

一个我TEM,苹果,既有价格和数量,但在不同的表。

Using a SQL join, these values become merged into one row!

使用SQL连接,这些值将合并为一行!

那么,为什么需要有关此内容的整篇文章? (So why do I need an entire article about this?)

In most cases, joining data won’t be as simple as the previous example. Oftentimes, we’ll have rows that can’t be joined because there isn’t the same value in the joining column for both tables.

在大多数情况下,合并数据不会像前面的示例那样简单。 通常,我们会有无法连接的行,因为两个表的连接列中的值都不相同。

For instance, what if there wasn’t a quantity for apple in the example above? How we handle what we do with rows like this depends on the type of SQL Join we choose.

例如,如果上面的示例中没有苹果数量,该怎么办? 处理此类行的方式取决于我们选择SQL Join的类型。

Image for post

There are four main types of joins: inner join, left join, right join, and full join. In this article, I’ll explain to you what each type entails.

联接主要有四种类型:内部联接,左联接,右联接和完全联接。 在本文中,我将向您解释每种类型的含义。

Image for post

Before going into everything, I think it’d be nice to mention that our tool Merge Spreadsheets is an easy to use tool that will easily perform all of this joining for you.

在介绍所有内容之前,我想很高兴地提到我们的工具“ 合并电子表格”是易于使用的工具,可以轻松地为您执行所有这些连接。

You can experiment with your spreadsheets to learn how these joins will look.

您可以尝试使用电子表格来了解这些联接的外观。

什么是内部联接? (What is an inner join?)

An inner join results in a table with rows where the values in the joining column are in both tables.

内部联接生成的表中具有行,其中联接列中的值都在两个表中。

To better understand this, let’s take a look at this example being joined on the item column:

为了更好地理解这一点,让我们看一下在item列上加入的示例:

Image for post

Both of the starting tables have a lot of different items, but only Apple and Orange are in both. So, the final result will only include Apple and Orange with their price and quantity values merged into the same row.

两个起始表都有很多不同的项目,但是只有Apple和Orange都在。 因此,最终结果将仅包括将价格和数量值合并到同一行的Apple和Orange。

什么是左联接? (What is a left join?)

A left join will include all of the rows in the left table (file one), regardless of if they’re in the right table.

左联接将包括表(文件一)中的所有行,无论它们是否在右表中。

Let’s take a look at the same tables as before, also being merged on the item column:

让我们看一下与以前相同的表,它们也被合并在item列上:

Image for post

Like with inner join, the final product of this join includes Apple and Orange. However, it also includes all the other rows from file one, even if they don’t have quantity values (those cells will be left blank)!

与内部联接一样,此联接的最终产品包括Apple和Orange。 但是,它也包括文件一中的所有其他行,即使它们没有数量值(这些单元格将留为空白)!

什么是正确的联接? (What is a right join?)

A right join is the exact opposite of a left join; it includes all the values in the right table (file two) regardless of what’s in the first table.

右连接与左连接完全相反; 它包括表(文件2)中的所有值,而不管第一个表中的内容如何。

Image for post

So, in the same example as before, this will include Apple and Orange while also including any other rows in file two!

因此,在与之前相同的示例中,这将包括Apple和Orange,同时还包括文件2中的任何其他行!

什么是完全加入? (What is a full join?)

A full join will combine all the data from both spreadsheets while merging the rows that can be merged.

完全联接将合并两个电子表格中的所有数据,同时合并可以合并的行。

Full join is definitely the way to go if you don’t want to exclude any data in your final result.

如果您不想在最终结果中排除任何数据,完全连接绝对是正确的选择。

As always, using the same two tables as before will yield a different result when using a full join.

与往常一样,使用完全连接时,使用与以前相同的两个表将产生不同的结果。

Image for post

All the rows from both tables are included and Apple and Orange become merged (as those are the only common items)!

两个表中的所有行都包括在内,Apple和Orange合并(因为这是唯一的常见项目)!

有趣的是,这会变得更加复杂吗? (Interesting, so does this get more complicated?)

It gets a little more complicated. There are a couple special cases that I’ll go into so that you’ll have a better understanding of how joining works!

它变得有点复杂。 我将介绍几种特殊情况,以便您对加入的工作方式有更好的了解!

如果我的数据重复了怎么办? (What if I have duplicates in my data?)

If you have duplicates in one table, they’ll also show up in your joined table depending on the join type.

如果您在一个表中有重复项,则它们还将显示在联接表中,具体取决于联接类型。

If there is a single row in one file with the same value in the joining column as multiple rows in the second file, those data in that single row will be repeated for each instance.

如果一个文件中的单行与第二个文件中的多行在连接列中具有相同的值,则将针对每个实例重复该单行中的那些数据。

For example, let’s look at the tables below being Inner joined on the Item column. In file one, there are two Orange rows while there’s only one in file two.

例如,让我们看一下在“ 项目”列上内部连接的下表。 在文件一中,有两个橙色行,而在文件二中只有一个。

Image for post

Joining this will include both of the unique rows from file one while repeating the data for quantity from file two!

加入此文件将包括文件1的两个唯一行,同时重复文件2的数量数据!

By the way, a LEFT join would also produce the same result

顺便说一句, LEFT连接也会产生相同的结果

我可以共同加入多个列吗? (Can I join with multiple columns in common?)

Yes! If you want to join a table based on multiple columns, each grouping will be classified as its own unique entity.

是! 如果要基于多个列联接表,则每个分组都将分类为自己的唯一实体。

For instance, in the example below, we’ll be Full joining on the Item and Price columns.

例如,在下面的示例中,我们将在“ 项目”和“ 价格”列上进行“ 完全连接”。

Image for post

The Apple row is the only one that’s merged because it’s the only one with the same Item and Price in both tables.

苹果行是唯一被合并的行,因为它是两个表中唯一具有相同项目价格的行

Instead of both of the Orange rows being merged, they are treated as different rows because their price values are different.

由于它们的价格值不同,因此不会将两个橙色行都合并,而是将它们视为不同的行。

So, everything is the same as before but now we look for the same values in two columns rather than just one.

因此,一切都与以前相同,但是现在我们在两列中寻找相同的值,而不仅仅是一列。

如果我的公用栏中有空白值怎么办? (What if I have a blank value in my common column?)

Each blank value in the column you’re joining on will be treated like any normal value. In other words, you can join on a blank value as usual.

您要加入的列中的每个空白值都将被视为任何常规值。 换句话说,您可以照常加入空白值。

Image for post

For example, in the tables above, there are blank values in both files in the item column. These will be treated as the same string and become joined! In the case of the example above, all types of joining will result in the same product.

例如,在上表中,项目列中的两个文件都有空白值。 这些将被视为相同的字符串并加入! 在上面的示例中,所有类型的连接都将产生相同的产品。

NOTE: While a blank value will be treated as any other string, a NULL value is different. NULL values denote nothing and are typically used in code. Each NULL value is treated as a unique entity and can’t be joined on. For more information, check out this article.

Let’s also take a look at a more comprehensive example with all of these special cases in it.

让我们也看看其中包含所有这些特殊情况的更全面的示例。

We will be performing a Left join on the Item and Price columns.

我们将在项目价格列上执行连接。

Image for post

When performing a left join, all the rows from the left file will be in the final product.

执行联接时,左文件中的所有行都将在最终产品中。

The Apple,$1 row is in both files, so the ID# and quantity for them will be merge.

Apple,$ 1行在两个文件中,因此它们的ID#和数量将合并。

Orange,$2 is only in the left file, so its quantity will remain blank.

橙色,$ 2仅在左侧文件中,因此其数量将保持空白。

Finally, we have a blank/blank row in the left file and two blank/blank rows in the second file. This means the the ID # for blank/blank in file one will be repeated twice to go with each quantity value in the second table!

最后,左侧文件中有一个空白行,第二个文件中有两个空白行。 这意味着文件1中空白/空白的ID#将重复两次,以与第二张表中的每个数量值对应!

And the fully blank row at the bottom will be ignored!

底部的空白行将被忽略!

所以...我们涵盖了所有内容吗? (So… have we covered everything?)

Yep! We just went over all the basics of SQL joins so you should be able to join tables with no problems now.

是的 我们仅介绍了SQL连接的所有基础知识,因此您现在应该可以毫无问题地连接表。

Feel free to experiment with your data in spreadsheets at Merge Spreadsheets because there is nothing like trying this out to really understand it.

可以在Merge Spreadsheets的电子表格中随意尝试数据,因为没有什么可以像尝试这种方法那样真正理解它了。

If you still have questions, don’t hesitate to reach out to info@lovespreadsheets.com!

如果您仍有疑问,请随时联系info@lovespreadsheets.com!

Want to learn more about how to Merge Spreadsheets? Check out our ultimate guide here!

想更多地了解如何合并电子表格? 在这里查看我们的最终指南!

翻译自: https://medium.com/@lovespreadsheets/a-brief-yet-comprehensive-introduction-to-sql-joins-de2fa412d2e

sql横着连接起来sql

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388429.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《Python》进程收尾线程初识

一、数据共享 from multiprocessing import Manager 把所有实现了数据共享的比较便捷的类都重新又封装了一遍,并且在原有的multiprocessing基础上增加了新的机制list、dict 机制:支持的数据类型非常有限 list、dict都不是数据安全的,需要自己…

北京修复宕机故障之旅

2012-12-18日 下午开会探讨北京项目出现的一些问题,当时记录的问题是由可能因为有一定数量的客户上来后,就造成了Web服务器宕机,而且没有任何时间上的规律性,让我准备出差到北京,限定三天时间,以及准备测试…

一般线性模型和混合线性模型_从零开始的线性混合模型

一般线性模型和混合线性模型生命科学的数学统计和机器学习 (Mathematical Statistics and Machine Learning for Life Sciences) This is the eighteenth article from the column Mathematical Statistics and Machine Learning for Life Sciences where I try to explain som…

《企业私有云建设指南》-导读

内容简介第1章总结性地介绍了云计算的参考架构、典型解决方案架构和涉及的关键技术。 第2章从需求分析入手,详细讲解了私有云的技术选型、资源管理、监控和运维。 第3章从计算、网络、存储资源池等方面讲解了私有云的规划和建设,以及私有云建设的总体原则…

太原冶金技师学院计算机系,山西冶金技师学院专业都有什么

山西冶金技师学院专业大全大家在考试之后对除了选择学校之外,还更关注专业的选择,山西冶金技师学院有哪些专业成了大家最为关心的问题。有些同学一般是选择好专业再选择自己满意的学校,下面小编将为你介绍山西冶金技师学院开设的专业及其哪些…

海南首例供港造血干细胞志愿者启程赴广东捐献

海南首例供港造血干细胞志愿者启程赴广东捐献。 张瑶 摄 海南首例供港造血干细胞志愿者启程赴广东捐献。 张瑶 摄 中新网海口1月23日电 (张茜翼 张瑶)海南省首例供港造血干细胞捐献者晶晶(化名)23日启程赴广东进行捐献,将于28号正式捐献采集造血干细胞,为…

如何击败Python的问题

Following the previous article written about solving Python dependencies, we will take a look at the quality of software. This article will cover “inspections” of software stacks and will link a free dataset available on Kaggle. Even though the title say…

KindEditor解决上传视频不能在手机端显示的问题

KindEditor自带的上传视频生成的HTML代码为<embed>&#xff0c;在手机端并不支持。于是可以自己在控件里增加生成video标签相关代码。 参考https://www.jianshu.com/p/047198ffed92。。 然而对着修改后没有成功&#xff0c;可能是那里没有改对吧。依然生成的是<embed&…

《独家记忆》见面会高甜宠粉 张超现场解锁隐藏技能

1月23日&#xff0c;由爱奇艺出品&#xff0c;小糖人联合出品的沉浸式成长练爱剧《独家记忆》在京举行粉丝见面会。爱奇艺高级副总裁陈宏嘉&#xff0c;爱奇艺副总裁、自制剧开发中心总经理、《独家记忆》总制片人戴莹&#xff0c;小糖人董事长、《独家记忆》总制片人朱振华&am…

计算机软件技术基础fifo算法,软件技术基础真题

一、填空1、数据结构按逻辑结构可分为两大类&#xff0c;它们分别是线性和非线性2.1、在长为n的顺序存储的线性表中插入和删除元素时所需移动元素的平均次数(等概率情况下)为&#xff1a;Einn/2&#xff0c;Ede(n-1)/22.2、顺序表有5个元素&#xff0c;设在任何位置上插入元素是…

NOI 2016 优秀的拆分 (后缀数组+差分)

题目大意&#xff1a;给你一个字符串&#xff0c;求所有子串的所有优秀拆分总和&#xff0c;优秀的拆分被定义为一个字符串可以被拆分成4个子串&#xff0c;形如$AABB$&#xff0c;其中$AA$相同&#xff0c;$BB$相同&#xff0c;$AB$也可以相同 作为一道国赛题&#xff0c;95分…

多元线性回归 python_Python中的多元线性回归

多元线性回归 pythonVideo Link影片连结 This episode expands on Implementing Simple Linear Regression In Python. We extend our simple linear regression model to include more variables.本集扩展了在Python中实现简单线性回归的方法 。 我们扩展了简单的线性回归模型…

关于apache和tomcat集群,线程是否占用实验

测试目的&#xff1a; 测试在apache入口的时候进入&#xff0c;当Tomcat的一个请求陷入死循环&#xff0c;或者线程进入循环无反应的时候&#xff0c;是否此时占用apache的线程资源。 测试原因&#xff1a; 如果要是影响&#xff0c;无论tomcat线程设置成多大&#xff0c;都…

爬虫之数据解析的三种方式

一&#xff0c;正则表达式解析 re正则就不写了&#xff0c;前面已经写入一篇很详细的正则表达式模块了~ 而且&#xff0c;在爬虫中&#xff0c;下面两种方式用的多一些~ 正则表达式&#xff1a;https://www.cnblogs.com/peng104/p/9619801.html 大致用法&#xff1a; pattern …

相对于硬件计算机软件就是,计算机的软件是将解决问题的方法,软件是相对于硬件来说的...

计算机网络管理软件是为计算机网络配置的系统软件。它负责对网络资源进行组织和管理&#xff0c;实现相互之间的通信。计算机网络管理软件包括网络操作系统和数据通信处理程序。前者用于协调网络中各计算机的操作系统及实现网络资源的传递&#xff0c;后者用于网络内的通信&…

数据冒险控制冒险_劳动生产率和其他冒险

数据冒险控制冒险Labor productivity is considered one of the most important indicators of a country’s well-being. However, we don’t know so much about it, let’s try to figure out how it is calculated, and how things are with it in the world (data source:…

Java后端WebSocket的Tomcat实现

原文&#xff1a;https://www.cnblogs.com/xdp-gacl/p/5193279.html 一.WebSocket简单介绍 随着互联网的发展&#xff0c;传统的HTTP协议已经很难满足Web应用日益复杂的需求了。近年来&#xff0c;随着HTML5的诞生&#xff0c;WebSocket协议被提出&#xff0c;它实现了浏览器与…

knn 邻居数量k的选取_选择K个最近的邻居

knn 邻居数量k的选取Classification is more-or-less just a matter of figuring out to what available group something belongs.分类或多或少只是弄清楚某个事物所属的可用组的问题。 Is Old Town Road a rap song or a country song?Old Town Road是说唱歌曲还是乡村歌曲…

EXTJS+JSP上传文件带进度条

需求来源是这样的&#xff1a;上传一个很大的excel文件到server&#xff0c; server会解析这个excel&#xff0c; 然后一条一条的插入到数据库&#xff0c;整个过程要耗费很长时间&#xff0c;因此当用户点击上传之后&#xff0c;需要显示一个进度条&#xff0c;并且能够根据后…

什么样的代码是好代码_什么是好代码?

什么样的代码是好代码编码最佳实践 (Coding Best-Practices) In the following section, I will introduce the topic at hand, giving you a sense of what this post will cover, and how each argument therein will be approached. Hopefully, this will help you decide w…