Sql server 如何在MSSQL中对多个匹配应用策略

Sql server 如何在MSSQL中对多个匹配应用策略,sql-server,Sql Server,预期o/p(需要连接两个表,然后第一次匹配为true,第二次匹配为false,如果不匹配也为false) 1,2,T 1,2,F 2,2,F请发布表格内容示例和预期输出示例 create table a ( col1 int, col2 int) create table b (col1 int,col2 int) insert b select 1,2 union select 1,2 insert a select 1,2 union select 2,2 SELECT col1,

预期o/p(需要连接两个表,然后第一次匹配为true,第二次匹配为false,如果不匹配也为false)

1,2,T
1,2,F

2,2,F

请发布表格内容示例和预期输出示例
create table a ( col1 int, col2 int)
create table b (col1 int,col2 int)

insert b
select 1,2
union
select 1,2

insert a
select 1,2
union
select 2,2
 SELECT col1, col2, 
     CASE WHEN (rownumber = 1 AND othercol is not null)
     THEN 'T' ELSE 'F' END col3
     FROM
        (
        Select a.col1, a.col2,b.col1 othercol, ROW_NUMBER()  OVER(Partition by a.col1 ,a.col2 order by a.col1,a.col2) rownumber 
        from  #a  a
        LEFT JOIN #b b ON a.col1 = b.col1 AND a.col2 = b.col2
        ) t