Click here to Skip to main content
15,890,609 members
Home / Discussions / Database
   

Database

 
Questionperformance? Pin
hassan azizi8-Oct-05 17:03
hassan azizi8-Oct-05 17:03 
QuestionSystem DB Pin
Ranoush7-Oct-05 21:55
Ranoush7-Oct-05 21:55 
AnswerRe: System DB Pin
S Douglas20-Oct-05 23:33
professionalS Douglas20-Oct-05 23:33 
QuestionGenerate Create Script will not show up in Database Project in VS.NET Pin
Pitchiah4u7-Oct-05 21:38
Pitchiah4u7-Oct-05 21:38 
Questioncheckbox in datagrid Pin
ahager7-Oct-05 7:07
ahager7-Oct-05 7:07 
QuestionManagment studio Pin
Bueto7-Oct-05 3:52
Bueto7-Oct-05 3:52 
AnswerRe: Managment studio Pin
Bueto9-Oct-05 22:54
Bueto9-Oct-05 22:54 
QuestionSQL Pin
shoaibnawaz6-Oct-05 10:34
shoaibnawaz6-Oct-05 10:34 
I am new to SQL.Smile | :)
I am facing a problem.D'Oh! | :doh:

I have two tables as under:

Sales
+-------+-------+---------------+---------------+
|ID	|Date	|ProductID	|Sold_Qty	|
+-------+-------+---------------+---------------+
|1	|5/25/05|1		|4		|
|2	|5/25/05|2		|3		|
|3	|5/26/05|1		|2		|
|4	|5/26/05|1		|1		|
|5	|5/26/05|2		|2		|
+-------+-------+---------------+---------------+

SalesReturn
+-------+-------+---------------+---------------+
|ID	|Date	|ProductID	|Returned_Qty	|
+-------+-------+---------------+---------------+
|1	|5/26/05|1		|2		|
|2	|5/27/05|2		|1		|
|3	|5/27/05|1		|2		|
+-------+-------+---------------+---------------+

How to create a query that can tell me about each product sales activity (How many sold and how many returned)
And can preview as under
+---------------+---------------+---------------+
|ProductID	|T_Sold_Qty	|T_Returned_Qty	|
+---------------+---------------+---------------+
|1		|7		|4		|
|2		|5		|1		|
+---------------+---------------+---------------+

Note: I have tried "SELECT SUM([Sold_Qty]) As T_Sold_Qty WHERE ProductID=1"
This query works only in one table and for only one ProductID

What about the following Query?

"SELECT Products.ProductID, (SELECT SUM([Sales.Sold_Qty]) As T_Sold_Qty FROM Sales WHERE Sales.ProductID=Products.ProductID), (SELECT SUM([SalesReturn.Returned_Qty]) As T_Returned_Qty FROM SalesReturn WHERE SalesReturn.ProductID=Products.ProductID) FROM Products,Sales, SalesReturn "



Shoaib Nawaz

-- modified at 16:38 Thursday 6th October, 2005
AnswerRe: SQL Pin
Colin Angus Mackay6-Oct-05 12:35
Colin Angus Mackay6-Oct-05 12:35 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 11:50
shoaibnawaz7-Oct-05 11:50 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 12:09
shoaibnawaz7-Oct-05 12:09 
GeneralRe: SQL Pin
Colin Angus Mackay7-Oct-05 13:12
Colin Angus Mackay7-Oct-05 13:12 
QuestionSQL Performance Question Pin
jgallen236-Oct-05 8:29
jgallen236-Oct-05 8:29 
AnswerRe: SQL Performance Question Pin
Colin Angus Mackay6-Oct-05 9:11
Colin Angus Mackay6-Oct-05 9:11 
GeneralRe: SQL Performance Question Pin
jgallen236-Oct-05 9:17
jgallen236-Oct-05 9:17 
QuestionExecuting SQL Script File Pin
KragAapie5-Oct-05 19:32
KragAapie5-Oct-05 19:32 
AnswerRe: Executing SQL Script File Pin
Colin Angus Mackay5-Oct-05 21:59
Colin Angus Mackay5-Oct-05 21:59 
QuestionHow to call stored procedure from update statement Pin
iluha5-Oct-05 15:54
iluha5-Oct-05 15:54 
AnswerRe: How to call stored procedure from update statement (edit) Pin
Nic Rowan6-Oct-05 1:55
Nic Rowan6-Oct-05 1:55 
QuestionImport/Export in MS Access Pin
suzie1005-Oct-05 8:38
suzie1005-Oct-05 8:38 
QuestionHelp with Cursors in Stored Procedures Pin
jszpila5-Oct-05 6:33
jszpila5-Oct-05 6:33 
AnswerRe: Help with Cursors in Stored Procedures [long reply] Pin
Colin Angus Mackay5-Oct-05 11:12
Colin Angus Mackay5-Oct-05 11:12 
AnswerRe: Help with Cursors in Stored Procedures [long reply] Pin
jszpila5-Oct-05 11:54
jszpila5-Oct-05 11:54 
GeneralRe: Help with Cursors in Stored Procedures [long reply] Pin
Colin Angus Mackay5-Oct-05 12:16
Colin Angus Mackay5-Oct-05 12:16 
QuestionLooking for the right forum Pin
Michael Hulthin4-Oct-05 21:42
Michael Hulthin4-Oct-05 21:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.