Identifying when there is more than 1 in a group based on grouped field

Posted by Brian Cascone on Stack Overflow See other posts from Stack Overflow or by Brian Cascone
Published on 2014-08-20T16:18:05Z Indexed on 2014/08/20 16:20 UTC
Read the original article Hit count: 153

Filed under:

Sorry for the bad description it is tough to explain in one sentence.

I have a dataset that has Cause field (RootCause) and an ID field (GroupID). Both can be many things but I need to identify where a GroupID has a multiple different rootcauses.

for example: RootCause GrpId AAA 111 BBB 222 CCC 111

I am looking to be able to identify that GrpId 111 has two different RootCauses.

This is what I have so far:

Select  [RootCause], GrpId, Count(GrpID) as CntGrpId
From DB.dbo.Table
Where DatatypeField <> ''
Group BY  [RootCause],GrpId

This results set visualy gives me enough information to identify what I am looking for, but i need something better. I am looking to return only the ones that have multiples.

Any ideas? Thanks

© Stack Overflow or respective owner

Related posts about tsql