-1

私はこれらのコードを持っています:

select case 
     when exists (select 1 
                  from table1
                  where id=608071) 
     then column1 
     else 0
  end as abc
from table1 where id=608071;

select decode(count(column1), 0, column1) abc
from (select column1
      from table1
      where id=608071) group by column1; 

そして、それらのどれも私にcolumn1、0、エラーを返しません。それは私にヌル、すなわち何も与えません。行は返されません。特定のIDが存在しない場合は0を取得する必要があります。ここの何が問題になっていますか?

4

2 に答える 2

1

これを試して!!

select case when exists (select 1 from table1 where id= '608071')  then  (select column1 from table1)  else '0' end as abc from dual
于 2013-03-05T07:08:07.657 に答える
0

これがあなたの要件であると仮定すると、「特定のIDが存在しない場合は0を取得する必要があります」

select
  nvl(T.COLUMN1, 0) COLUMN1_OR_ZERO
from
  DUAL D left join(
    select
      *
    from
      TABLE1
    where
      id = '608071') T on (1=1)

このクエリでは、テーブルを 1 回だけスキャンします。

于 2013-03-05T08:11:04.283 に答える