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 |
Spica66
Starting Member
23 Posts |
Posted - 2012-10-01 : 15:56:16
|
I have a table with quantities of inventory tags assigned to different plants.Some of the plants have more than one group assigned to them. For display, I want the total assigned to that plant.This code:SELECT t.PlantID ,Sum(t.QtyAssigned)qty FROM dbo.inv_TagAssignments tGROUP BY t.plantID, t.qtyAssignedOrder by PlantId ascGives this result:P10 4500P11 400P12 600P14 700P17 200P18 100P18 300P2 6500P3 400P5 500P5 5500P69A 3000P69B 6000P7A 3500P7B 5000P9 300As you can see, P5 is listed twice. How can I rewrite this query to group P5 together and show the total qty assigned as 6000? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-01 : 16:10:02
|
[code]SELECT t.PlantID,Sum(t.QtyAssigned)qtyFROM dbo.inv_TagAssignments tGROUP BY t.plantIDOrder by PlantId asc[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2012-10-01 : 16:12:04
|
Don't GROUP BY qtyAssigned.[CODE]SELECT t.PlantID,Sum(t.QtyAssigned)qtyFROM dbo.inv_TagAssignments tGROUP BY t.plantID --, t.qtyAssignedOrder by PlantId asc[/CODE]=================================================We are far more concerned about the desecration of the flag than we are about the desecration of our land. -Wendell Berry |
|
|
|
|
|