Author |
Topic |
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2012-06-20 : 14:03:03
|
I have one table that has types of fines in it. It has lastName, FirstName, TypeID, courtCost, Fine, Totalcost, DocketNum, CaseIDThere will be 2 records that has the same DocketNum, CaseID. The one type ID, I need to get lastName, FirstName, TypeID, courtCost, Fine. The second I need to get Totalcost So here are the 2 recordslastName, FirstName, TypeID, courtCost, Fine, Totalcost, DocketNum, CaseIDSmith, Bob, 1, 34.00, 400.00, 0 , 345678, 8787Smith, Bob, 2, 0, 0, 60.00 , 345678, 8787So I need to only bring back one record like so.Smith, Bob, 34.00, 400.00, 60.00 , 345678, 8787Notice I added the 60.00 from TypeID 2What would the SQL look like?DaveHelixpoint Web Developmenthttp://www.helixpoint.com |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-06-20 : 14:12:06
|
SELECT lastName,firstName,sum(courtCost) as courtCost,sum(fine) as fine,sum(TotalCost) as TotalCost,DocketNum,CaseIDFROM youtTableGROUP BY lastName,firstName,DocketNum,CaseIDEveryday I learn something that somebody else already knew |
 |
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2012-06-20 : 14:22:26
|
But there are other TypeID with the same DocketNum and CaseID. I need just trye 1 and 2DaveHelixpoint Web Developmenthttp://www.helixpoint.com |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-06-20 : 14:35:43
|
SELECT lastName,firstName,sum(courtCost) as courtCost,sum(fine) as fine,sum(TotalCost) as TotalCost,DocketNum,CaseIDFROM youtTableWHERE typeID in (1,2)GROUP BY lastName,firstName,DocketNum,CaseIDJimEveryday I learn something that somebody else already knew |
 |
|
|
|
|