Link to home
Start Free TrialLog in
Avatar of larisa1970
larisa1970

asked on

What is wrong with this query

SELECT       
Qty,
OrderID,
SubTotal= (SELECT SUM(Qty) FROM [tblTradesFill] c      WHERE  c.OrderID=OrderID )
FROM  [tblTradesFill]

Snapshot of the results:
2000      8329520-47      4212194
2000      8329521-47      4212194
100      8329532-47      4212194
100      8329532-47      4212194
1800      8329532-47      4212194
2000      8329533-47      4212194

SubTotal should have a summarized quantity per each orderID. My code however returns a grand total.
It's driving me crazy. Please help
Avatar of Aneesh
Aneesh
Flag of Canada image

can you please post the desired output
Which database?
Avatar of larisa1970
larisa1970

ASKER

200      8329520-47      200
2000      8329521-47      2000
100      8329532-47      2100
100      8329532-47      2100
1900      8329532-47      2100
2000      8329533-47      2000
sql server 2008
your query is fine
how can it give these for the same orderID "8329532-47"

100      8329532-47      2100
100      8329532-47      2100
1900      8329532-47      2100
2000      8329533-47      2000
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the last one is different - 33, not 32
(I should have made up some clear data, not just paste)
Thank you! Thank you! Thank you!
Who would've thought that alias will make a difference