I'm trying to make an SQL query across 3 tables and am having trouble doing it.
I have the following tables:
Associates:
AssociateID | AssociateName | Email | Phone
Clients:
ClientID | ClientName | ClientDescription | AssociateID
Sales:
TxnID | ClientID | ProductID | Quantity
(it's a simplized version of my database)
What the basic association is that associates manage clients and the clients list their sales on my site of the various products they sell. What I want to somehow query, given an AssociateID, and find out how many distinct() clients an associate has (Count()) when sum()ming up all the quantities of products sold for that client under the sales table (for example, setting the theshold at sum(quantity) = 100)
Can this be done using the JOIN command, or do I need to run a bunch of loops to run through each line of the Sales table in order to count each distinct client's sales?
Thanks a lot