0
点赞
收藏
分享

微信扫一扫

sql 临时表代替left join提高性能


L表数据量:77179753

J表数据量:42201

原表left join :

select count(1) from l left join j on j.userID=l.userid 
where l.appID=1000 and l.loginTime>='2018-01-01' and l.loginTime<'2018-02-01'

等半天不出结果!



临时

表left join :


select l.* into #tmp
from l where l.appID=1000 and l.loginTime>='2018-01-01' and l.loginTime<'2018-02-01'

select count(1) from #tmp l left join j on j.userID=l.userid

查询结果:45459


速度很快!



举报

相关推荐

0 条评论