这两个代码的运行逻辑是什么,出来的结果会一致吗
原代码:
select a.id,
sum(case when t.applydate between '20200101' and '20200331' then (t.city_amt+t.county_amt) end) Q1,
sum(case when t.applydate between '20200401' and '20200630' then (t.city_amt+t.county_amt) end) Q2,
sum(case when t.applydate between '20200701' and '20200930' then (t.city_amt+t.county_amt) end) Q3,
sum(case when t.applydate between '20201001' and '20201231' then (t.city_amt+t.county_amt) end) Q4
from test_0227 a left join mk_dzs t on a.id=t.primary_id
where t.applydate between '20200101' and '20201231'
and t.code like 'AA101%'
group by a.id
修正代码:
select a.id,
sum(case when t.applydate between '20200101' and '20200331' then (t.city_amt+t.county_amt) end) Q1,
sum(case when t.applydate between '20200401' and '20200630' then (t.city_amt+t.county_amt) end) Q2,
sum(case when t.applydate between '20200701' and '20200930' then (t.city_amt+t.county_amt) end) Q3,
sum(case when t.applydate between '20201001' and '20201231' then (t.city_amt+t.county_amt) end) Q4
from test_0227 a left join (select * from mk_dzs t1
where t1.applydate between '20200101' and '20201231'
and t1.budgetsubjectcode like 'AA101%')t
on a.id=t.primary_id
group by a.id
1、从SQL本身来说,两个SQL的结果是不一样的(在一定的数据特殊分布情况下,你会得到两个SQL执行结果一致的错误结论)
2、首先,两个SQL中的 mk_dzs 表中的条件不同:前一个是:t.code like 'AA101%',后一个是:t1.budgetsubjectcode like 'AA101%'
3、其次,LEFT JOIN 中,如果右表中的字段出现在 WHERE 条件上且无 NULL 判定,则,其效果跟 INNER JOIN 一致,即,第一个SQL其实是一个INNER JOIN,而不是LEFT JOIN
4、排除我第 2 点说的字段不同的情况外,将第一个 SQL 的 WHERE 条件放到 LEFT JOIN 的条件中,即可达到第二个SQL同样的效果:
from test_0227 a left join mk_dzs t on a.id=t.primary_id and t.applydate between '20200101' and '20201231' and t.code like 'AA101%'
alter index index_name rebuild online ;
alter index index_name unusable ;
regedit
】按回车键,即可打开注册表,在地址栏输入:计算机\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1
查看右侧名称为:ORACLE_SID
的数据数值,是否为当前系统运行实例的SID,如果不是请修改,然后关闭注册表即可。
D、数据库端口(默认为1521)为防火墙阻止连接,在防火墙中开放此端口即可。