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 |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-09-20 : 07:17:58
|
Boboy Ponce writes "Hi All;I have an MSSQL Table named SALES and has column DATE, ITEM_ID, ITEM_DESC, QTYM UNITPRICE, AMOUNTIt has a records such as below:DATE ITEM_ID DESCRIPTION UNITPRICE QTY AMOUNT---- -------- ------------ --------- --- -------08/01 S2601 Dining Chair US$ 25.50 2 51.0008/05 S2601 Dining Chair US$ 12.50 1 15.0008/10 B1101 Table US$ 5.00 5 25.00Now, I create a query that will sum the column QTY, AMOUNT that has the same ITEM_ID:*****SELECT TOP 100 PERCENT item_id, item_desc,UnitPrice, SUM(QTY) AS Expr1, SUM(AMOUNT) AS Expr2 FROM dbo.SalesGROUP BY date, item_id, item_desc, unitprice, qty, Amount ORDER BY item_id *****When I execute the above code, nothing happens and the result is just the same as above rows.Is there anything wrong with my code?Please help.Regards.Boboy " |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-09-20 : 07:18:52
|
Remove Amount and Qty from the GROUP BY clause:SELECT TOP 100 PERCENT item_id, item_desc,UnitPrice, SUM(QTY) AS Expr1, SUM(AMOUNT) AS Expr2 FROM dbo.SalesGROUP BY date, item_id, item_desc, unitprice ORDER BY item_id |
 |
|
|
|
|
|
|