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
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
can you please post the desired output
Which database?
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
2000 8329521-47 2000
100 8329532-47 2100
100 8329532-47 2100
1900 8329532-47 2100
2000 8329533-47 2000
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the last one is different - 33, not 32
(I should have made up some clear data, not just paste)
(I should have made up some clear data, not just paste)
ASKER
Thank you! Thank you! Thank you!
Who would've thought that alias will make a difference
Who would've thought that alias will make a difference