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 |
|
gagani
Posting Yak Master
112 Posts |
Posted - 2012-05-09 : 05:24:58
|
| for the given table,orderid product quantity100 A 1100 B 2101 B 4101 A 3101 C 1101 D 3100 A 2101 D 5I need a query for the outputorderid product quantity100 A 3100 B 2101 B 4101 A 3101 C 1101 D 8for a given orderid, if there are two entries for the same product, the quantities are summed up. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-09 : 05:44:49
|
SELECT OrderID, Product, SUM(Quantity) AS QuantityFROM dbo.GivenTableGROUP BY OrderID, ProductORDER BY OrderID, Product N 56°04'39.26"E 12°55'05.63" |
 |
|
|
vinu.vijayan
Posting Yak Master
227 Posts |
Posted - 2012-05-09 : 06:25:03
|
quote: Originally posted by SwePeso SELECT OrderID, Product, SUM(Quantity) AS QuantityFROM dbo.GivenTableGROUP BY OrderID, ProductORDER BY OrderID, Product N 56°04'39.26"E 12°55'05.63"
+1 Swepeso. Can't be done any better.N 28° 33' 11.93148"E 77° 14' 33.66384" |
 |
|
|
|
|
|