Re: [SQL ] 找交集
※ 引述《retsamsu (haha)》之銘言:
: ※ 引述《asio1 (牛奶)》之銘言:
: : 其實我是在做dataming的作業,在尋找資料的特性
: : 所以資料庫才會這樣大
: : 可以請你解釋一下做法嗎 我用的是mySQL 的環境
: : 因為其實table_1 與table_2 都是兩個query出的結果,所以是沒有index的
: : 但是各別執行都花不到一秒 但是做卡氏積就太大了
: 那就照 flakchen 說的試試看吧
: select count(*) from table_1 where table_1.col1 in (select col1 from table_2)
select count(*) from table_1 a
where exists (
select col1 from table_2 b where a.col1 = b.col1
)
用exists據說會比in有效率
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.73.235.198
※ 編輯: swangs 來自: 203.73.235.198 (06/17 01:43)
討論串 (同標題文章)