I have two tables
One table connects “client ID” with “product id”
TABLE A
ClientID ProductID
1 2
1 4
1 6
2 3
2 5
Then there is another table that logs the amount of time spent with a product:
TABLE B
ProductID Time Date_added
2 10 (datetime)
4 2 (datetime)
2 3 (datetime)
4 1 (datetime)
How do I combine two queries:
One query to get all the product id’s associated with a client
SELECT ProductID FROM TABLE_A where ClientID = 1
Then get a monthly sum of all the time spent with those products?
SELECT SUM(time) from Table_B WHERE DATEPART(month, Date_added) = 8 AND ProductID = (products from the previous query?)
Sounds like you want a join statement, taking a shot in the dark but probably
This will show the total of time for all products as grouped by the Client ID. This will also include clients that did not have any time spent on products for the month