我有這樣獲取列值的組合,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