2017-03-20 12 views
1

パラメータ(:PRODUCT_ID)を2回渡しました。私は渡すことができますどのように:私はそのようにこの問題を解決しようとするクエリ以下以下のSQLクエリに対して単一のパラメータを渡す方法

select count(1) 
from (
    select count(1) album_fa_counter 
    from actual_configs ac 
    where ac.config_id = :PRODUCT_ID 
     and exists (
      select 1 
      from config_participants cp 
      where CONTRIBUTOR_CATEGORY = 'Featured Artist' 
       and cp.gpid = ac.gpid 
      ) 
    ) a, 
    (
     select count(1) matching_track_fa_counter 
     from actual_tracks at1, 
      actual_configs ac1 
     where at1.gpid = ac1.gpid 
      and ac1.config_id = :PRODUCT_ID 
      and exists (
       select 1 
       from recording_participants rp, 
        config_participants cp 
       where cp.CONTRIBUTOR_CATEGORY = 'Featured Artist' 
        and cp.gpid = at1.gpid 
        and cp.participant_name = rp.participant_name 
        and rp.CONTRIBUTOR_CATEGORY = 'Featured Artist' 
        and rp.isrc = at1.isrc 
       ) 
     ) b 
where a.album_fa_counter = 0 
    or b.matching_track_fa_counter > 0; 

答えて

0

あなたのコードにあまりにも多くの変更を加えることなく、簡単な方法は、あなたの変数が含まれていると、あなたのクエリに参加中にそれを使用するCTEを使用して次のようになります。さておき、私はあなたのコードを編集したよう

with yourVariable(val) as (select :PRODUCT_ID from dual) 
select count(1) 
from (
    select count(1) album_fa_counter 
    from actual_configs ac, 
     yourVariable 
    where ac.config_id = yourVariable.val 
     and exists (
      select 1 
      from config_participants cp 
      where CONTRIBUTOR_CATEGORY = 'Featured Artist' 
       and cp.gpid = ac.gpid 
      ) 
    ) a, 
    (
     select count(1) matching_track_fa_counter 
     from actual_tracks at1, 
      actual_configs ac1, 
      yourVariable 
     where at1.gpid = ac1.gpid 
      and ac1.config_id = yourVariable.val 
      and exists (
       select 1 
       from recording_participants rp, 
        config_participants cp 
       where cp.CONTRIBUTOR_CATEGORY = 'Featured Artist' 
        and cp.gpid = at1.gpid 
        and cp.participant_name = rp.participant_name 
        and rp.CONTRIBUTOR_CATEGORY = 'Featured Artist' 
        and rp.isrc = at1.isrc 
       ) 
     ) b 
where a.album_fa_counter = 0 
    or b.matching_track_fa_counter > 0; 

書き直すことなく、もう少し努力してANSI SQLに書き直す方がはるかに良いでしょう。

+0

このクエリは私のために働いています..thanks – Madhava

0

ために一度だけPRODUCT_ID:

With 
a as 
(select count(1) album_fa_counter 
from actual_configs ac 
where ac.config_id = :PRODUCT_ID 
    and exists (
     select 1 
     from config_participants cp 
     where CONTRIBUTOR_CATEGORY = 'Featured Artist' 
      and cp.gpid = ac.gpid), 

b as 
(
    select count(1) matching_track_fa_counter 
    from actual_tracks at1, 
     actual_configs ac1, 
     a 
    where at1.gpid = ac1.gpid 
     and ac1.config_id = ac.config_id 
     and exists (
      select 1 
      from recording_participants rp, 
       config_participants cp 
      where cp.CONTRIBUTOR_CATEGORY = 'Featured Artist' 
       and cp.gpid = at1.gpid 
       and cp.participant_name = rp.participant_name 
       and rp.CONTRIBUTOR_CATEGORY = 'Featured Artist' 
       and rp.isrc = at1.isrc 
      ) 
Select count (1) 
from a,b 
Where 
a.album_fa_counter = 0 
or b.matching_track_fa_counter > 0; 

今、データベースは、実際のテーブルとしてaとbを見ているので、あなたが使用したパラメータaは、表内で通常の使用可能な値と見なすべきです。 これがうまくいくと思います。

関連する問題