mysql補集合計算

mysql補集計算方法:
 
兩表是1對多關係,user_id是關聯字段,兩表的數據量都是千萬級別的
 
 
  • 子查詢實現
select count( *), sum(total_money) from A w
where user_id not in (
select user_id from B
)
 
耗時爲75s
 
  • 錶鏈接實現
 
select count( *), sum(total_money) from A left join B on A.user_id = B.user_id
where B.user_id is null
 
耗時39s
 
 
在mysql中,用錶鏈接的方式計算補集,速度上更優。


相關文章
相關標籤/搜索