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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Group by on joined tables

Author  Topic 

zokhox
Starting Member

4 Posts

Posted - 2012-06-27 : 20:01:58
Hi
I have 3 tables as:

Worker (WorkerID, WorkerName),
WorkOnProject (ProjectID, WorkerID, NumberDays)
AbsentOnProject (ProjectID, WorkerID, AbsentDays) "AbsentDays is a negative number"

I need to write a query which shows WorkerID, WorkerName and a column which shows the result of (NumberDays + AbsentDays) for each worker.

Please note that there could be multiple Absent records for each worker in the AbsentOnProject table. So I think I should Sum AbsentDays for each worker first then add the result to NumberDays in the WorkOnProject

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-28 : 02:17:15
Do you want a result for each Project that a Worker has worked on or just the sum for a Worker regardless of Projects?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -