Home Getting distinct count in SQL Server
Reply: 0

Getting distinct count in SQL Server

user4702
1#
user4702 Published in September 19, 2018, 11:23 am

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
share|improve this question

1 Answer 1

active oldest votes
up vote 3 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33351 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO