Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

What is wrong with this query

Posted on 2009-12-31
8
Medium Priority
?
162 Views
Last Modified: 2012-05-08
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
0
Comment
Question by:larisa1970
  • 4
  • 3
8 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26154412
can you please post the desired output
0
 
LVL 77

Expert Comment

by:peter57r
ID: 26154432
Which database?
0
 

Author Comment

by:larisa1970
ID: 26154437
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:larisa1970
ID: 26154478
sql server 2008
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 26154501
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
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 26154515
SELECT      
Qty,
OrderID,
SubTotal= (SELECT sum(a.qty) FROM tblTradesFill a     WHERE  c.OrderID=a.OrderID )
FROM  tblTradesFill c
0
 

Author Comment

by:larisa1970
ID: 26154532
the last one is different - 33, not 32
(I should have made up some clear data, not just paste)
0
 

Author Comment

by:larisa1970
ID: 26154538
Thank you! Thank you! Thank you!
Who would've thought that alias will make a difference
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question