Q:

Count distinct rows where another column not the same

I would like to know how to do a count on NUM, where CODE is not distinct?
So the count would be Two!?
CODE    NUM
T1  1001
T1  1001
T1  1001
T2  1002
T2  1002
T3  1003
T3  1003
T4  1003
T5  1004
T5  1004
T5  1004
T6  1005
T7  1005
T7  1005

A:

 Try Below code :

 SELECT NUM , COUNT(*)
 FROM #table
 GROUP BY NUM
 HAVING COUNT(DISTINCT CODE) > 1

