理解exists count

Nalternative發表於2012-10-20

兩個查詢出來的結果一樣嗎?理解exists的判斷條件。

select 1
from dual d
where exists(
select 1
from dual d2
where d.DUMMY=d2.DUMMY
and 1=2
)
/
select 1
from dual d
where exists(
select count(*)
from dual d2
where d.DUMMY=d2.DUMMY
and 1=2
)

下邊的查詢結果一樣嗎? count是如何計數的。

create table tj.temp_test(id number(8),name varchar2(20));
insert into tj.temp_test(id) values(1);
select count(*) from tj.temp_test;
select count(*) from tj.temp_test;
select count(case when id=3 then 4 end) from  tj.temp_test;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25323853/viewspace-746845/,如需轉載,請註明出處,否則將追究法律責任。

相關文章