2017-03-20 1 views
1

매개 변수 (: PRODUCT_ID)를 두 번 전달했습니다. 내가 전달할 수있는 방법 : 나는 그런 식으로이 문제를 해결하려고 할 쿼리 아래아래의 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

: 여담으로

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

이 쿼리는 나를 위해 작동합니다 .. 감사합니다. – 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는 표의 정상적인 사용 가능한 값으로 간주되어야합니다. 희망이 있습니다. 코드, 간단한 방법이 변수를 포함하고 그것은 당신의 쿼리에서 조인을 사용하는 CTE를 사용하여 수에 너무 많은 변경없이

관련 문제