[英]How to use where clause inside NOT EXISTS in sql?
我需要在sql中的NOT EXISTS
子句中放置where条件。
在下面需要检查重复记录,在下面的SQL查询中我需要把Date ='2012-05-07'和SecurityId ='52211'但问题是使用内部连接而且我是新的bie没有得到如何请把这些条款请帮忙。
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'
)
更新后,我想(??)你想要这个吗?
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.