TSQL中實現ORACLE的多列IN 多列匹配。

來源:互聯網
上載者:User
期望效果:(我是拿到一對關係去另一表中的一對關係去對比)select * From Empoylee Where(Address1,Address2) in(Select Address1,Address2From EmpoyleeAdressesWhere Country = 'Canada')以上無法實現用這種方案也可以實現 不過速度很慢的select * from               (select (zcbm ||','||fwbm) as t from T_FWZC ) tt where t not in(select (zcbm ||','||fwbm) as c from T_ZC_FC_GX)解決方案1:用exists判斷select a.* From Empoylee aWhere exists    (select 'A' from EmpoyleeAdresses b     Where        b.Country = 'Canada'            and a.Address1=b.Address1            and a.Address2=b.Address2        )解決方案2:用inner join內連結select *FromEmpoyleeinner join EmpoyleeAdressesonEmpoylee.Address1=EmpoyleeAdresses.Address1andEmpoylee.Address2=EmpoyleeAdresses.Address2WhereEmpoyleeAdresses.Country = 'Canada')select * fromEmpoylee eminner join EmpoyleeAdresses emAonem.Address1=emA.Address1andem.Address2=emA.Address2andemA.Country = 'Canada'解決方案3:表關聯select a.*From Empoylee a ,  (Select  Address1,Address2 From EmpoyleeAdresses   Where  Country = 'Canada') bWherea.Address1=b.Address1anda.Address2 = b.Address2主觀感覺方案1更快一些,客觀上,還沒在查詢分析器裡用"顯示執行計畫"看哪種寫法效率高些. 如果是Delete語句,寫法如下:Delete From Empoylee Where exists    (select 'A' from EmpoyleeAdresses b     Where        b.Country = 'Canada'            and Empoylee.Address1=b.Address1            and Empoylee.Address2=b.Address2        )注意Delete from 後的表不能用別名~

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.