Wednesday, July 31, 2013

Get a Max and Min using CountDistinct

Try this query,



SELECT Country,Topic,(SELECT Distinct Count(Question_Key)
FROM ExampleTable B WHERE B.Country=A.Country AND B.Topic=A.Topic) as CountDistinct,
MAX(Question_Key) MaxQuestion,
MIN(Question_Key) MinQuestion
FROM ExampleTable A
GROUP BY Country,Topic





Regards, RSingh


No comments:

Post a Comment