※ 引述《Whynopeople (whynopeople)》之銘言:
: 各位前輩好,
: 最近在整理資料遇上一些語法問題。
: 有兩張資料表table_1及table_2
: 想要的到result_table的結果。
: table 1
: =================
: | CUI | STR |
: -----------------
: | 1 | Hi |
: -----------------
: | 2 | wow |
: =================
: table 2
: ==================
: | CUI_1 | CUI_2 |
: ------------------
: | 1000 | 1 |
: ------------------
: | 2 | 1002 |
: ------------------
: | 1 | 2 |
: ------------------
: | 2 | 1 |
: ==================
: 結果:
: result_table
: =============================
: | CUI_1 | STR | CUI_2 | STR |
: -----------------------------
: | 1 | Hi | 2 | wow |
: -----------------------------
: | 2 | wow | 1 | Hi |
: =============================
: 我們試著下以下條件
: select table2.CUI_1, table1.STR, table2.CUI_1, table.STR
: from table1 , table2
: where table2.CUI1 in (select table.cui from table2)
: and
: table2.CUI2 in (select table1.cui from table1)
: 但也許是這樣寫效率太差(table1有6000筆資料,table2有百萬筆資料)
: 得不到回應
: 而且我們都覺得這語法似乎達不到預期結果
: 還請版上前輩們可否指導一下
: 謝謝
select c.CUI_1, a.STR, c.CUI_2, b.STR
from table1 a, table1 b, table2 c
where a.CUI = c.CUI_1 and b.CUI = c.CUI_2
也不知道這樣寫效率會不會比較好XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.31.126