K
keliie
Hello,
I'm building a query that shows the total sales value of our company's
widgets over time. I have the following tables:
1. A table with the various widget types
2. A table with units sold for each widget type by date
3. A table with prices for each widget type (including date price was
entered)
My problem is that my query is returning multiple results for units
sold each time the price is updated. For example:
- Assume Widget A is sold on Day 1 and Day 2
- Assume Widget A's price is updated on Day 1 (i.e., Price 1), and
again on Day 2 (i.e., Price 2)
Query results show the following records:
- Widget A sales on Day 1 at Price 1
- Widget A sales on Day 1 at Price 2
- Widget A sales on Day 2 at Price 1
- Widget A sales on Day 2 at Price 2
Having only a basic understanding of Queries, I understand the problem
that I've encountered, however I haven't been able to solve it. I've
tried using a combination of criteria (e.g., Price Date >= Sale Date),
Total functions (e.g., Last as opposed to Group By), selecting only
distinct rows, and modification of join properties. However, I haven't
had any success.
I know there must be an easy answer, can someone point me in the right
direction?
Thanks,
Kelii
SQL:
SELECT tblMenuMaster.Menu_Category, tblMenuMaster.Menu_Type,
tblMenuMaster.Menu_Description_ID, tblSalesMaster.Sale_Date,
tblSalesDetails.Menu_Item_Count_Sold, tblMenuPrice.Menu_Price_Date,
tblMenuPrice.Menu_Item_Price
FROM (tblMenuMaster INNER JOIN tblMenuPrice ON
tblMenuMaster.Menu_Description_ID = tblMenuPrice.Menu_Description_ID)
INNER JOIN (tblSalesMaster INNER JOIN tblSalesDetails ON
tblSalesMaster.Sales_ID = tblSalesDetails.Sales_ID) ON
tblMenuMaster.Menu_Description_ID = tblSalesDetails.Menu_Description_ID
GROUP BY tblMenuMaster.Menu_Category, tblMenuMaster.Menu_Type,
tblMenuMaster.Menu_Description_ID, tblSalesMaster.Sale_Date,
tblSalesDetails.Menu_Item_Count_Sold, tblMenuPrice.Menu_Price_Date,
tblMenuPrice.Menu_Item_Price
HAVING (((tblMenuMaster.Menu_Description_ID)="458 THE PAGODA") AND
((tblMenuPrice.Menu_Price_Date)<=[Sale_Date]));
I'm building a query that shows the total sales value of our company's
widgets over time. I have the following tables:
1. A table with the various widget types
2. A table with units sold for each widget type by date
3. A table with prices for each widget type (including date price was
entered)
My problem is that my query is returning multiple results for units
sold each time the price is updated. For example:
- Assume Widget A is sold on Day 1 and Day 2
- Assume Widget A's price is updated on Day 1 (i.e., Price 1), and
again on Day 2 (i.e., Price 2)
Query results show the following records:
- Widget A sales on Day 1 at Price 1
- Widget A sales on Day 1 at Price 2
- Widget A sales on Day 2 at Price 1
- Widget A sales on Day 2 at Price 2
Having only a basic understanding of Queries, I understand the problem
that I've encountered, however I haven't been able to solve it. I've
tried using a combination of criteria (e.g., Price Date >= Sale Date),
Total functions (e.g., Last as opposed to Group By), selecting only
distinct rows, and modification of join properties. However, I haven't
had any success.
I know there must be an easy answer, can someone point me in the right
direction?
Thanks,
Kelii
SQL:
SELECT tblMenuMaster.Menu_Category, tblMenuMaster.Menu_Type,
tblMenuMaster.Menu_Description_ID, tblSalesMaster.Sale_Date,
tblSalesDetails.Menu_Item_Count_Sold, tblMenuPrice.Menu_Price_Date,
tblMenuPrice.Menu_Item_Price
FROM (tblMenuMaster INNER JOIN tblMenuPrice ON
tblMenuMaster.Menu_Description_ID = tblMenuPrice.Menu_Description_ID)
INNER JOIN (tblSalesMaster INNER JOIN tblSalesDetails ON
tblSalesMaster.Sales_ID = tblSalesDetails.Sales_ID) ON
tblMenuMaster.Menu_Description_ID = tblSalesDetails.Menu_Description_ID
GROUP BY tblMenuMaster.Menu_Category, tblMenuMaster.Menu_Type,
tblMenuMaster.Menu_Description_ID, tblSalesMaster.Sale_Date,
tblSalesDetails.Menu_Item_Count_Sold, tblMenuPrice.Menu_Price_Date,
tblMenuPrice.Menu_Item_Price
HAVING (((tblMenuMaster.Menu_Description_ID)="458 THE PAGODA") AND
((tblMenuPrice.Menu_Price_Date)<=[Sale_Date]));