sql语句结构
select rownum as tempNum,
.....
from (select .....
where....
order by AD.detailaddressstr, CUSTOMEREN.CUSTOMERADDRSTR) temp
where (case when ... then ...else end);
如果查询结果列中有rownum,查询出的数据会比不添加rownum的结果列多出很多。
Oracle的版本时10.2.0.1.0.
在某个库里出现了这种情况
这是where后面的条件
where (case
when 1 is null then
'x'
else
(case
when 1 = 0 and temp.number0 = 0 and 0 = 2 then
'x'
when 1 = 1 and temp.number1 > 0 and 1 = 2 then
'x'
when 1 = 1 and temp.number2 > 0 and 2 = 2 then
'x'
else
'y'
end)
end)
temp.number是最外层查询出来的结果列,在有rownom时,发现where后只有temp.number>0时条数是对的,加上temp.number=0就出现条数多。
但是把rownum去掉,查询上面的语句条数就正常。
where (case
when 1 is null then
'x'
else
(case
when 1 = 1 and temp.number1 > 0 and 1 = 2 then
'x'
when 1 = 1 and temp.number2 > 0 and 2 = 2 then
'x'
else
'y'
end)
end)
这样条数是对的。