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.pswp.cn/news/388429.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388429.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388429.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

霸縣計算機學校,廊坊中專排名2021

一、招生專業類別專業名稱r制招生人政培養日標備注預備技師數控加工(中心操做工)340格養掌握先進斂p加ot知識,是部創新精神和較a空際操作能力,4了ftc71h0iwro感娶顯型人于-宇缺畢讓生培養具備電氣白動化oirm和o技能,叢事電氣設督安裝、調試、…

《Python》進程收尾線程初識

一、數據共享 from multiprocessing import Manager 把所有實現了數據共享的比較便捷的類都重新又封裝了一遍,并且在原有的multiprocessing基礎上增加了新的機制list、dict 機制:支持的數據類型非常有限 list、dict都不是數據安全的,需要自己…

北京修復宕機故障之旅

2012-12-18日 下午開會探討北京項目出現的一些問題,當時記錄的問題是由可能因為有一定數量的客戶上來后,就造成了Web服務器宕機,而且沒有任何時間上的規律性,讓我準備出差到北京,限定三天時間,以及準備測試…

計算機學院李世杰,有關辦理2016級轉專業學生相關手續通知

《有關辦理2016級轉專業學生相關手續通知》由會員分享,可在線閱讀,更多相關《有關辦理2016級轉專業學生相關手續通知(4頁珍藏版)》請在技術文庫上搜索。1、1 關于辦理 2016 級轉專業學生相關手續的通知 各學院(部)、各相關部門: 根據西安科技…

一般線性模型和混合線性模型_從零開始的線性混合模型

一般線性模型和混合線性模型生命科學的數學統計和機器學習 (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章從計算、網絡、存儲資源池等方面講解了私有云的規劃和建設,以及私有云建設的總體原則…

vs2005的webbrowser控件如何接收鼠標事件

這個問題來自論壇提問,vs2005的webbrowser控件如何接收鼠標事件,很多事情其實自己動動腦子就有辦法的。主要是3步,給dom對象插入js腳本去響應鼠標-〉通過url跳轉去通知webbrowser-〉截獲跳轉事件去c#中處理 示例代碼: using System; using…

[TimLinux] Python 迭代器(iterator)和生成器(generator)

1. 可迭代對象 from collection import Iterableclass Iterable(metaclassABCMeta):...def __iter__(self): # 只實現了__iter__ 方法while False:yield None 能夠在 for ... in obj:中使用的對象(obj)就是一個可迭代對象。 2. 迭代器 from …

太原冶金技師學院計算機系,山西冶金技師學院專業都有什么

山西冶金技師學院專業大全大家在考試之后對除了選擇學校之外,還更關注專業的選擇,山西冶金技師學院有哪些專業成了大家最為關心的問題。有些同學一般是選擇好專業再選擇自己滿意的學校,下面小編將為你介紹山西冶金技師學院開設的專業及其哪些…

海南首例供港造血干細胞志愿者啟程赴廣東捐獻

海南首例供港造血干細胞志愿者啟程赴廣東捐獻。 張瑤 攝 海南首例供港造血干細胞志愿者啟程赴廣東捐獻。 張瑤 攝 中新網海口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&…

湖北經濟學院的計算機是否強,graphics-ch11-真實感圖形繪制_湖北經濟學院:計算機圖形學_ppt_大學課件預覽_高等教育資訊網...

第十一章 真實感圖形技術1,簡單光照明模型2,多邊形繪制方法3,透明4,整體觀照明模型5,光線跟蹤算法第十章 真實感圖形繪制光照模型 (Illumination Model):計算某一點的光強度的模型11.1 真實感圖形的 特點? 能反映物體表面顏色和亮度的細微變化? 能表現物體表面的質感? 能通過…

ARP攻擊網絡上不去,可以進行mac地址綁定

紅色部分是需要敲的命令 Microsoft Windows [版本 6.1.7600] 版權所有 (c) 2009 Microsoft Corporation。保留所有權利。 C:\Users\dell>arp -s 顯示和修改地址解析協議(ARP)使用的“IP 到物理”地址轉換表。 ARP -s inet_addr eth_addr [if_addr] ARP -d inet_addr [if…

《獨家記憶》見面會高甜寵粉 張超現場解鎖隱藏技能

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 …