I have a SQL Server 2005 table called Users:
UserID | Date | Name | Issues | On | Off | Value
1 | 02/02/2010 | John | 3 | True | False | 75
2 | 07/23/2010 | Nate | 7 | False | True | 50
3 | 02/12/2010 | John | 5 | False | True | 45
4 | 01/29/2010 | John | 8 | True | False | 65
5 | 09/01/2010 | Nate | 6 | True | False | 30
6 | 12/07/2010 | John | 2 | False | True | 40
7 | 07/18/2010 | Nate | 10 | True | False | 80
I want to get the SUM of Issues for each Name, the SUM of Value when On is true, the SUM of Value when Off is true between given dates:
Name | No of issues| SUM of ON | SUM of OFF
John | 18 | 140 | 85
Nate | 23 | 110 | 50
Thank you!
The following should do the trick: