SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 14th, 2004, 02:14 PM
Blarney Blarney is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 Blarney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old February 14th, 2004, 02:58 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
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

Reply With Quote
  #3  
Old February 14th, 2004, 04:02 PM
Blarney Blarney is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 Blarney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Nested Solution perhaps?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT