의 열 값의 조합을 받고 나는이는 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
의 마지막 그룹을 선택 할 수 있습니다. 이것은 조합이
인 조합이 있기 때문에 조합을보고 그룹 (즉, rowid)을 가져 오는 tsql 쿼리가있는 유일한 그룹이기 때문입니다.
는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