|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Nested Solution perhaps?
Two tables
ProductPurchases : Product code, product qty Purchase : Order Date column Using Inner join like so : "SELECT * FROM ProductPurchases INNER JOIN Purchase ON ProductPurchases.PurchaseID = Purchase.PurchaseID WHERE (Purchase.OrderDate >= '2/1/2004 00:00:00' AND Purchase.OrderDate <= '2/13/2004 23:59:59') AND (ProductPurchases.Code = 'ac90')" can easily retrieve such : ProductCode | ProductQty | OrderDate ac90 | 4 | 2/1/2004 ac90 | 6 | 2/1/2004 ... ac90 | 12 | 2/13/2004 ac90 | 1 | 2/13/2004 What I'm now struggling with is how to consolidate rows with same date to sum on the Qty field to acheive: ProductCode | ProductQty | OrderDate ac90 | 10 | 2/1/2004 ... ac90 | 13 | 2/13/2004 I understand 'sum(field) AS something' but am having trouble nesting or aggregating the desired results into one statement. I'm trying to work toward generating a visual graph which should be fundemental to produce once I can aggregate the qty for each order date. Hopefully I have explained it well enough. Would look forward to any direction or samples to view. Thanks |
|
#2
|
||||
|
||||
|
Try this
Code:
SELECT A.ProductCode, SUM(A.ProductQty) As 'TotalProducts', B.OrderDate FROM ProductPurchases A INNER JOIN Purchase B ON (A.PurchaseID = B.PurchaseID) WHERE (B.OrderDate >= '2/1/2004 00:00:00' AND B.OrderDate <= '2/13/2004 23:59:59') AND (B.Code = 'ac90') GROUP BY B.OrderDate, A.Code |
|
#3
|
|||
|
|||
|
Thanks Memnoch
'SELECT ProductPurchases.Code, SUM(ProductPurchases.Qty) As TotalProducts, Purchase.OrderDate FROM ProductPurchases INNER JOIN Purchase ON (ProductPurchases.PurchaseID = Purchase.PurchaseID) WHERE (Purchase.OrderDate >= '2/1/2004 00:00:00' AND Purchase.OrderDate <= '2/13/2004 23:59:59') AND (ProductPurchases.Code = 'cc90') GROUP BY Purchase.OrderDate, ProductPurchases.Code' Still not aggregating rows on similar dates... Stats (graph) Result cc90 2/1/2004 10:07:00 AM 1 cc90 2/1/2004 5:41:00 PM 10 cc90 2/1/2004 7:11:00 PM 3 cc90 2/2/2004 11:40:00 AM 12 cc90 2/2/2004 12:56:00 PM 12 cc90 2/2/2004 10:53:00 PM 3 cc90 2/3/2004 12:23:00 PM 2 cc90 2/3/2004 4:25:00 PM 2 cc90 2/3/2004 9:26:00 PM 1 cc90 2/4/2004 12:43:00 AM 7 cc90 2/4/2004 12:45:00 AM 3 cc90 2/4/2004 1:53:00 PM 12 cc90 2/5/2004 8:20:00 AM 2 cc90 2/5/2004 2:58:00 PM 3 ADO doesn't provide for quering a return recordset which would be one hack ... but I certain there is away to consolidate rows with ... oh heck just noticing now..the CONVERT(DATETIME .... results in all unique rows .. will try formating as simple date context... likely my problem with your solution ...will let you know how I make out. Much appreciated |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Nested Solution perhaps? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|