Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Find Clients with Sales in more than one country

Author  Topic 

SQLNoob81
Starting Member

38 Posts

Posted - 2012-11-02 : 06:36:44
Hi All

I have a clients table and an orders table. I need to find clients with orders in more than one [Country] in the orders table.

I then need to count the order for clients who have orders in more than one country.

Your help is appreciated.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-02 : 06:47:52
You can do both in one query:
SELECT
clientId, COUNT(Orders) AS OrderCount
FROM
OrdersTable
GROUP BY
clientId
HAVING
COUNT(DISTINCT country) > 1;
Go to Top of Page
   

- Advertisement -