20万数据的子查询外加入where条件,执行速度减慢?

下面一段SQL,如果不加where str1 = '1' 执行速度很快,仅需5秒,但是加入where查询之后,无法产生结果,总体数据量仅有20万,各位大拿给看看是什么原因。
SQL如下:
select

count(distinct str1)

from
(

select
    a1.str0
    ,a1.str4
    ,case when a2.str3=1 then '1' else '0' end as str1
from table1 a1
left join table2 a2
on a1.str0=a2.str0

)
where str1 = '1'

参与14

提问者

星坠天宇
软件开发工程师合肥瑞耘信息

问题状态

  • 发布时间:2018-02-27
  • 关注会员:4 人
  • 问题浏览:3110
  • 最近回答:2018-02-28
  • X社区推广