我有这样获取列值的组合,TSQL
rowid deltaValue Applicable
1 r n/d
1 w n/d
1 m n/d
2 r n/d
2 w n/d
2 m n/d
3 r n/d
3 w n/r
3 m n/d
数据库结构,所以基本上我只想选择“ROWID”,即rowid=3
的最后一组。这是因为它是唯一一个具有n/d, n/r
的组合的组合,是否有一个tsql查询将只查看组合并拉取组(即rowid)。 这是我到目前为止有:
select *
from table
where 1=1
and deltaValue in ('r','w','m')
and (( 1=(case when [DeltaValue] = 'r' and [Applicable]='n/r' then 1 else 0 end)
and 1=(case when [DeltaValue] = 'w' and [Applicable]='n/d' then 1 else 0 end)
and 1=(case when [DeltaValue] = 'm' and [Applicable]='n/d' then 1 else 0 end)
) OR
( 1=(case when [DeltaValue] = 'r' and [Applicable]='n/d' then 1 else 0 end)
and 1=(case when [DeltaValue] = 'w' and [Applicable]='n/r' then 1 else 0 end)
and 1=(case when [DeltaValue] = 'm' and [Applicable]='n/d' then 1 else 0 end)
) OR
( 1=(case when [DeltaValue] = 'r' and [Applicable]='n/d' then 1 else 0 end)
and 1=(case when [DeltaValue] = 'w' and [Applicable]='n/d' then 1 else 0 end)
and 1=(case when [DeltaValue] = 'm' and [Applicable]='n/r' then 1 else 0 end)
)
)
输出:
3 r n/d
3 w n/r
3 m n/d
你能告诉我们你想要的输出吗? –
我已经添加了输出 – masfenix