2014-02-12 51 views
0

我已經寫了下面的查詢count函數應該返回0或空的,如果沒有行選擇

select process_status_count 
from (select count(*) as process_status_count from prod.process_status) 
where process_status_count <> 18; 

要求:我想應該process_status_count則返回0狀態「process_status_count <> 18」不履行(process_status_count是18)。

process_status_count沒有返回結果(也不爲空)。

請建議我需要做什麼更改,如果是process_status_count = 18,則結果爲零或爲空。

+0

計數可以在下面的查詢我使用和它工作正常返回0,但不能爲null – Miller

回答

0

嘗試下面的查詢,

SELECT CASE process_status_count WHEN 18 THEN process_status_count ELSE 0 END 
FROM(
    SELECT COUNT(*) AS process_status_count 
    FROM prod.process_status 
    ); 
1

使用情況說明;

select case when process_status_count = 18 then 0 else process_status_count end from (select count(*) as process_status_count from sidewinder.process_status); 
+0

感謝你的努力:) – DJJ

+0

= 18 then 0 else process_status_count end from(從sidewinder.process_status中選擇count(*)作爲process_status_count); – DJJ

0
SQL> select count(*), decode(count(*), 18, count(*), 0) fullfill_cond 
    2 from user_objects 
    3/

    COUNT(*) FULLFILL_COND               
---------- -------------               
     937    0               

SQL> select count(*), decode(count(*), 937, count(*), 0) fullfill_cond 
    2 from user_objects 
    3/

    COUNT(*) FULLFILL_COND               
---------- -------------               
     937   937 
0

希望這會幫助你:選擇情況下,當process_status_count:

with process_status 
as 
(
select 'Y' as process_status_count from dual 
connect by level <=18 
) 
select decode(count(process_status_count),18,0,count(process_status_count)) as status 
from process_status 
相關問題