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中,用表连接的方式计算补集,速度上更优。




原文地址:https://www.cnblogs.com/lostpaddle/p/3368935.html