2012-05-07 14 views
0

sqlの中に条件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

関連する問題