I have three tables:
- companies
- customers for those companies
- addresses for each customer
I want to know how many companies in my database has the accounts with more that 100 addresses linked to them.
I tried this but it didn't work:
SELECT
COUNT(DISTINCT c.Id)
FROM
Customers cu
INNER JOIN
Addresses ad ON ad.Customer = cu.Id
INNER JOIN
Companies c ON cu.company = c.Id
GROUP BY
cu.ID
HAVING
COUNT(ad.ID) > 100