下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、深入理解LEFTJOINa表,b表如下*3cccunt_i.dchamlact2lbact3fb=*date_JkeyacGOiint._idchannelspend:20L90B01actlfb50.0D00SQL執(zhí)行順序,先執(zhí)行join,得到一個(gè)join的組合結(jié)果,然后執(zhí)行where,where對(duì)join的整體結(jié)果進(jìn)行過濾。leftjoin的執(zhí)行結(jié)果:selecta.account_idasa_account_id,a.channelasa_channel,b.account_idasb_account_id,b.channelasb_channel,b.date_key,b.spendf
2、romaleftjoinbonb.account_id=a.account_ida_account_ida_chaimelb_account_idb_channeldate_keyspend1act3fbact3fb20190603150,00002sctlfbactl2019080150.0000相同字段來自不同表的結(jié)果并不相同,所以在用where做篩選時(shí)應(yīng)注意相同字段表的選擇。幾種連接方式的比較:1.where條件選用a.channelselecta.account_idasa_account_id,a.channelasa_channel,b.account_idasb_account_
3、id,b.channelasb_channel,b.date_key,b.spendfromaleftjoinbonb.account_id=a.account_idwherea.channel=fb耳a_aceDunl_ida_chatmlb_aecouni_idb_channeldaie_keyspend1act3fbact3fb20190303150.00002actlftactlfb2019080150.00002.where條件選用b.channelselecta.account_idasa_account_id,a.channelasa_channel,b.account_idas
4、b_account_id,b.channelasb_channel,b.date_key,b.spendfromaleftjoinbonb.account_id=a.account_idwhereb.channel=fb*a_accouiit_ica_chaniBlb_accaunl_idb_channeldatc_keyspend:actSfbact3tb20190303150.0000where條件選用a.channel,b.date_key寫在where中selecta.account_idasa_account_id,a.channelasa_channel,b.account_ida
5、sb_account_id,b.channelasb_channel,b.date_key,b.spendfromaleftjoinbonb.account_id=a.account_idwherea.channel=fbanddate_key=20190801*3_accoLint_ida_ch3imsLb_accoimt_idb_chanr:91date_kevspend1actlfbactlfb20190801EiO.0000where是對(duì)leftjoin后的所有結(jié)果進(jìn)行篩選,將篩選所有滿足date_key條件的,而date_key只有b表存在,所以只會(huì)對(duì)b表進(jìn)行篩選,對(duì)a表只會(huì)篩選與b
6、表存在相同account_id的,相當(dāng)于使用join。where條件選用b.channel,b.date_key寫在where中selecta.account_idasa_account_id,a.channelasa_channel,b.account_idasb_account_id,b.channelasb_channel,b.date_key,b.spendfromaleftjoinbonb.account_id=a.account_idwhereb.channel=fbanddate_key=20190801耳a_accDunl_ida_channelb_3CC0UHL_idb_ch
7、anneldare_keyspend:3Cl3fbact3ft20190S03150.0000b.date_key寫在leftjoin條件中,where條件選用a.channel(只有這一種寫法可以得出spend為空時(shí)返回account_id)selecta.account_idasa_account_id,a.channelasa_channel,b.account_idasb_account_id,b.channelasb_channel,b.date_key,b.spendfromaleftjoinbonb.account_id=a.account_idanddate_key=20190
8、801wherea.channel=fb*a_accDunt_ida_channelb_account_idb_channeldatekeyspend:act3fbaci3ft20190S03150.00002&ctlactlfb2019030150.GOODb.date_key寫在leftjoin條件中,where條件選用b.channelselecta.account_idasa_account_id,a.channelasa_channel,b.account_idasb_account_id,b.channelasb_channel,b.date_key,b.spendfromaleftjoinbonb.account_id=a.account_idanddate_key=20190801whereb.channel=fb*a_accoint_ia_zhannElb_cco_mt_id_chameldate_keyspaid1acLdfbfb2319082315C.DOOC如果想要得到a中存在而b中不存在的數(shù)據(jù),貝Uwhere過濾條件中不能使用來自b表的,因?yàn)閎表中數(shù)據(jù)有缺失,將只過濾出b表中b.channel存在的數(shù)據(jù);只存在于b表而a表沒有的字段也不能使用,將只過濾出b表中該字段存在的數(shù)據(jù)??偨Y(jié):1注意相同字段表的選擇,w
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025振動(dòng)沉管灌注樁整體機(jī)械出租合同
- 2025不動(dòng)產(chǎn)權(quán)籍調(diào)查技術(shù)咨詢服務(wù)合同
- 課題申報(bào)參考:凌家灘史前玉器藝術(shù)價(jià)值挖掘與傳承創(chuàng)新路徑研究
- 學(xué)科交叉融合與創(chuàng)新能力提升
- 會(huì)展合同管理與風(fēng)險(xiǎn)防范考核試卷
- 二零二五年度森林碳匯樹木種植項(xiàng)目合同4篇
- 2025年滬教版選擇性必修1歷史下冊階段測試試卷
- 2025年新世紀(jì)版九年級(jí)地理上冊階段測試試卷
- 2025年冀教版九年級(jí)地理上冊月考試卷
- 2025年華師大版選擇性必修1化學(xué)下冊月考試卷
- 2024-2025學(xué)年北京石景山區(qū)九年級(jí)初三(上)期末語文試卷(含答案)
- 第一章 整式的乘除 單元測試(含答案) 2024-2025學(xué)年北師大版數(shù)學(xué)七年級(jí)下冊
- 春節(jié)聯(lián)歡晚會(huì)節(jié)目單課件模板
- 中國高血壓防治指南(2024年修訂版)
- 糖尿病眼病患者血糖管理
- 抖音音樂推廣代運(yùn)營合同樣本
- 教育促進(jìn)會(huì)會(huì)長總結(jié)發(fā)言稿
- 北師大版(2024新版)七年級(jí)上冊數(shù)學(xué)第四章《基本平面圖形》測試卷(含答案解析)
- 心理調(diào)適教案調(diào)整心態(tài)積極應(yīng)對(duì)挑戰(zhàn)
- 噴漆外包服務(wù)合同范本
- JT-T-390-1999突起路標(biāo)行業(yè)標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論