Home Getting distinct count in SQL Server
Reply: 0

Getting distinct count in SQL Server

user544
1#
user544 Published in July 17, 2018, 7:22 pm

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
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO