2012-05-07 6 views
0

조건부에 NOT EXISTS 절을 넣어야합니다. 아래에서SQL에서 NOT EXISTS 내부에서 where 절을 사용하는 방법은 무엇입니까?

내가 '2012-05-07이'와 SecurityId = '52211' 을하지만, 문제는 내부 조인 사용 = 날짜를 넣을 필요가 있고 내가있어 SQL 쿼리 아래 그에 대한 중복 기록을 체크 할 필요가 새 덧붙이는 방법을 얻지 못하는 곳에 절을 도와주세요.

SELECT DISTINCT 

    SecurityPriceId 

FROM 
    dbo.Indicative Bond 
    INNER JOIN 
    dbo.BondPrice BondPrice ON 
     Indicative.SecurityId = BondPrice.SecurityId AND 
     BondPrice.SecurityPriceSourceId = @SecurityPriceSourceComposite 
WHERE 
    Date = @Date -- Date='2012-05-07' like this 
    AND 
    NOT EXISTS 
    (
     SELECT 
      'z' 
     FROM 
      dbo.Reporting_BondPrices 
    WHERE 
     Reporting_BondPrices.SecurityId = BondPrice.SecurityId AND 
     Reporting_BondPrices.Date = BondPrice.Date 
     --how can i put Date='2012-05-07' and SecurityId='52211'     
    ) 

답변

2

업데이트가 완료되면 (??) 원하는 사항이 무엇인가요? 질문을 디코딩에서

SELECT DISTINCT 

    BondPrice.SecurityPriceId 

FROM 
    dbo.Reporting_BondIndicative Reporting_BondIndicative 
    INNER JOIN 
    dbo.BondPrice BondPrice ON 
     Reporting_BondIndicative.SecurityId = BondPrice.SecurityId AND 
     BondPrice.SecurityPriceSourceId = @SecurityPriceSourceComposite 
WHERE 
    BondPrice.Date = @Date -- BondPrice.Date='2012-05-07' like this 
    AND 
    NOT EXISTS 
    (
     SELECT 
      'z' 
     FROM 
      dbo.Reporting_BondPrices 
    WHERE 
     Reporting_BondPrices.SecurityId = BondPrice.SecurityId AND 
     Reporting_BondPrices.Date = BondPrice.Date 
     --how can i put Date='2012-05-07' and SecurityId='52211'     
     --simply put them in with and 
     and Reporting_BondPrices.SecurityId='52211' and Reporting_BondPrices.Date='20120507' 
    ) 

이전 시도 :

당신은 다음과 같이 테이블을 별칭을 수 있습니다

select ... 
from table as t1 --t1 will be the outer table 
where not exists(select ... 
       from table as t1 --t2 will be the inner table 
       where t1.column1=t2.column1 and t1.column2<>t2.column2) 

난 그냥 내 두 조건을 둘 필요가
+0

내가 어떻게 할 수 있니? – Neo

+0

? 그들은'어디에'안에 있습니다. – Blindy

+0

업데이트 됨 내 질문에 도움이 필요하십시오. – Neo

관련 문제