需将以下语句进行改变:
select sum(d_amount) from check_all
where (cost_code='830' or (cost_code='910' and d_cost_code='830')) and dist=0;
改变为:
select sum(d_amount) from check_all
where d_cost_code='830'
_________________________________________________ ;
要求:空白区域SQL语句可以出现'910',但不能出现‘830’急求高手,感觉要用正则表达式的知识
select sum(d_amount) from check_all
where (cost_code='830' or (cost_code='910' and d_cost_code='830')) and dist=0;
改变为:
select sum(d_amount) from check_all
where d_cost_code='830'
_________________________________________________ ;
要求:空白区域SQL语句可以出现'910',但不能出现‘830’急求高手,感觉要用正则表达式的知识
SELECT SUM(d_amount)
FROM check_all
WHERE ( cost_code = '830'
OR ( cost_code = '910'
AND d_cost_code = '830'
)
)
AND dist = 0 ;--上面这句就等效于下面这句 不知道楼主是什么意思
select sum(d_amount) from check_all
where d_cost_code='830' AND dist = 0 ;
因其他条件的制约限制,所以需要将原来的语句,改变为
select sum(d_amount) from check_all
where d_cost_code='830'
_________________________________________________ ;需将where条件拆分为2部分,其中一部分d_cost_code='830'是固定的,而另外一部分则要求里面不能出现‘830’数值;
除非cost_code只有'830','910' 两个值
and cost_code='910' and dist=0
or cost_code='830' and dist=0但是出现了830
改为:
and cost_code='910' and dist=0
or cost_code='8'+'30' and dist=0
本意是:830不出现在空白部分,这部分变为通用部门,与830无关,因该语句会加入group by进一步演化为通用语句