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
larisa1970Asked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT      
Qty,
OrderID,
SubTotal= (SELECT sum(a.qty) FROM tblTradesFill a     WHERE  c.OrderID=a.OrderID )
FROM  tblTradesFill c
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
can you please post the desired output
0
 
peter57rCommented:
Which database?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
larisa1970Author Commented:
200      8329520-47      200
2000      8329521-47      2000
100      8329532-47      2100
100      8329532-47      2100
1900      8329532-47      2100
2000      8329533-47      2000
0
 
larisa1970Author Commented:
sql server 2008
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
0
 
larisa1970Author Commented:
the last one is different - 33, not 32
(I should have made up some clear data, not just paste)
0
 
larisa1970Author Commented:
Thank you! Thank you! Thank you!
Who would've thought that alias will make a difference
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.