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.
| Author |
Topic |
|
MsLady
Starting Member
5 Posts |
Posted - 2009-12-30 : 11:10:24
|
| I am working on getting summed output based on differing values within one column. I have the following:SELECT dbo.CPRRC.Description, dbo.CPRRB.Code, dbo.CPRRD.Form, SUM(dbo.CPRRD.Cost) AS CostFROM dbo.CPRRCINNER JOIN dbo.CPRRD ON dbo.CPRRC.Code = dbo.CPRRD.Cat INNER JOIN dbo.CPRRB ON dbo.CPRRD.BIFK = dbo.CPRRB.BCodeGROUP BY dbo.CPRRB.Code, dbo.CPRRD.Form, dbo.CPRRC.DescriptionHAVING (dbo.CPRRD.Form = 'A') OR (dbo.CPRRD.Form = 'B')ORDER BY dbo.CPRRBm.CodeCurrent OutputDescription Code Form Cost Building 1234L A 100Building 1234R B 200Computer 2587L A 1000Computer 2587R B 1500Transportation 6854L A 3750Transportation 6854R B 7500Furniture 1973L A 10250Furniture 1973R B 27500Truck 1000L A 45000Desired OutputDescription CostBuilding 300Computer 2500Transportation 11250Furniture 37750Truck 45000 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-30 : 11:16:05
|
This?SELECT dbo.CPRRC.Description,SUM(dbo.CPRRD.Cost) AS CostFROM dbo.CPRRCINNER JOINdbo.CPRRD ON dbo.CPRRC.Code = dbo.CPRRD.Catwhere dbo.CPRRD.Form in('A','B')GROUP BY dbo.CPRRC.Description |
 |
|
|
brian147
Starting Member
10 Posts |
Posted - 2009-12-30 : 11:20:45
|
| just delete the unwanted columns from the SELECT list and the GROUPBY listeg:SELECT dbo.CPRRC.Description, SUM(dbo.CPRRD.Cost) AS CostetcGROUP BY dbo.CPRRC.Descriptionetc |
 |
|
|
brian147
Starting Member
10 Posts |
Posted - 2009-12-30 : 11:23:43
|
| i was a bit slow there, the "aged yak" got in just before me. |
 |
|
|
MsLady
Starting Member
5 Posts |
Posted - 2009-12-30 : 11:46:57
|
| Vijayisonly,Thank you very much.It worked as expected.MsLady. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-30 : 12:42:45
|
| You're welcome. |
 |
|
|
|
|
|