HAVING Count(DISTINCT ...

  • Thread starter Thread starter Ahlgren
  • Start date Start date
A

Ahlgren

Basically I got a query which should look like this:

SELECT CustID
FROM Country
GROUP BY CustID
HAVING Count (DISTINCT CountryCode) >2;

Unfortunately Access does not support Count DISTINCT. Does any one have a
solution?

Sample data:

CustID CountryCode
1 AA
1 BB
1 BB
2 AA
2 BB
2 AA
2 DD
3 DD

In the given example it should only show CustID 2, as only that custumer got
more than 2 UNIQUE country entries.
 
Try:

SELECT CustID
FROM
(SELECT DISTINCT CustID, CountryCode
FROM Country)
GROUP BY CustID
HAVING Count(CountryCode) > 2
 
Back
Top