将查询转换为IF EXISTS

时间:2014-07-25 11:07:32

标签: sql-server exists

如何将以下代码转换为IF EXISTS?所以想要返回ic.min值,它小于c.min和c.geolevel = ic.study_geolevel和ic。[geog] = c。[geog]

select ic.[min]   
from [dbo].[ICov] ic,  
[dbo].[cov]  c
where 
    ic.[geog]=c.[geog] and 
    c.geolevel=ic.study_geolevel AND 
    c.min<ic.min

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT  ic.[min]
FROM    [dbo].[ICov] AS ic
WHERE   EXISTS (SELECT 1
                FROM   [dbo].[cov] AS c 
                WHERE  ic.[geog]  = c.[geog] AND
                       c.geolevel = ic.study_geolevel AND 
                       c.min < ic.min)