TYPE ID SUB_ID DATA
M 1000 10 {stuff}
M 1000 20 {stuff}
M 1000 30 {stuff}
M 1000 40 {stuff}
W 1000 10 {stuff}
W 1000 20 {stuff}
W 1000 30 {stuff}
W 1000 35 {stuff}
W 1000 36 {stuff}
W 1000 40 {stuff}
I want to join on ID and SUB_ID but report out only the odd rows that exist with TYPE = 'W' but not TYPE = 'M'. So, in this case, I would want to report out only
WITH TypeCounts
AS
(
SELECT [Type], ID, Sub_ID, [Data]
,COUNT(*) OVER (PARTITION BY ID, Sub_ID) AS TypeCount
FROM YourTable
)
SELECT [Type], ID, Sub_ID, [Data]
FROM TypeCounts
WHERE [Type] = 'W'
AND TypeCount = 1;