Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Turnover by product group by month

Author  Topic 

AmonRa
Starting Member

1 Post

Posted - 2009-10-16 : 04:28:24
Hello there. I've a question about a query I want to create in MsAccess. (I understand the basics of SQL.)

I am running a webshop and I want to be able to analyse the orders. Therefore I want to create a list with all categories and the sales/turnover within that category within in month. So, for example:

Date | Category | Turnover(amount)
2009-01 | Softdrinks | 4000
2009-01 | Coffee | 2044
2009-01 | Tea | 5295
2009-02 | Softdrinks | 6000
2009-02 | Coffee | 1156
2009-02 | Tea | 7234
etc.etc.

My database looks like this:

NavigationGroup
NavigationGroupID | Description

ProductGroup
ProductID | NavigationGroupID.

OrderHeader
OrderID | CreationDate

OrderProduct
ProductID | OrderID | Amount | Price


I created this SQL Query, but Access is running out of memory when I want to run it. What am I doing wrong?

SELECT 
YEAR(oh.CreationDate) AS year,
MONTH(oh.CreationDate) AS month,
ng.Description,
SUM(op.Amount) AS total
FROM
NavigationGroup ng,
OrderHeader oh,
OrderProduct op,
ProductGroup pg
WHERE
YEAR(oh.CreationDate)=2009
AND op.OrderID=oh.OrderID
AND op.ProductID=pg.ProductID
AND pg.NavigationGroupID=ng.NavigiationGroupID
GROUP BY
YEAR(oh.CreationDate),
MONTH(oh.CreationDate),
ng.Description;
   

- Advertisement -