Hi everyone,
Very new here!
I'm creating a database to keep track of orders and stock nothing too complicated. Its virtually finished, just one little bit left which I'm not sure how to do. Hopefully someone can help me!
Database description.
I have a Customer Table (Showing customer details address etc)
A Product Table (Product ID etc also OS(Opening Stock for each product))
A Production Table (Product ID, Producewk1, producewk2, producewk3, producewk4)
A Order Table (Customer Name, Product ID, Orderwk1, orderwk2, order wk3, orderwk4)
At the moment I have a query which works out the total order of each product (from any customer) for each week separately (1-4). It also works out the stock left for each week by subtracting the order from the opening stock in the Product Table.
Here's the sql for that query
---------------------
SELECT [product id] AS Product_Code, SUM([wk 1 order]) AS Orders_For_WK1, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk1 AS Stock_Left_WK1, SUM([wk 2 order]) AS Orders_For_WK2, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk2 AS Stock_Left_WK2, SUM([wk 3 order]) AS Orders_For_WK3, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk3 AS Stock_Left_WK3, SUM([wk 4 order]) AS Orders_For_WK4, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk4 AS Stock_Left_WK4
FROM [order table]
GROUP BY [product id];
-------------
But this is what I want to change/improve the stock part of it with help!
Here is what I'd like to try and do but don't know how!!?
Stock_Left_WK1 = (ProductTable.OS - orders_for_wk1)
Stock_Left_WK2 = ( (Stock_Left_WK1 - orders_for_wk2) + (Production.ProduceWk1) )
Stock_Left_WK3 = ( (Stock_Left_WK2 - orders_for_wk3) + (Production.ProduceWk2) )
Stock_Left_WK4 = ( (Stock_Left_WK3 - orders_for_wk4) + (Production.ProduceWk3) )
Please can someone help me? Really stuck on this one!
If you need me to try and explain some more don't hesitate to ask.
Thanks for any help whatsoever.
Paul
Very new here!
I'm creating a database to keep track of orders and stock nothing too complicated. Its virtually finished, just one little bit left which I'm not sure how to do. Hopefully someone can help me!
Database description.
I have a Customer Table (Showing customer details address etc)
A Product Table (Product ID etc also OS(Opening Stock for each product))
A Production Table (Product ID, Producewk1, producewk2, producewk3, producewk4)
A Order Table (Customer Name, Product ID, Orderwk1, orderwk2, order wk3, orderwk4)
At the moment I have a query which works out the total order of each product (from any customer) for each week separately (1-4). It also works out the stock left for each week by subtracting the order from the opening stock in the Product Table.
Here's the sql for that query
---------------------
SELECT [product id] AS Product_Code, SUM([wk 1 order]) AS Orders_For_WK1, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk1 AS Stock_Left_WK1, SUM([wk 2 order]) AS Orders_For_WK2, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk2 AS Stock_Left_WK2, SUM([wk 3 order]) AS Orders_For_WK3, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk3 AS Stock_Left_WK3, SUM([wk 4 order]) AS Orders_For_WK4, (SELECT [OS] FROM [Product Table] WHERE [Product id]=[order table].[Product id])-Orders_For_Wk4 AS Stock_Left_WK4
FROM [order table]
GROUP BY [product id];
-------------
But this is what I want to change/improve the stock part of it with help!
Here is what I'd like to try and do but don't know how!!?
Stock_Left_WK1 = (ProductTable.OS - orders_for_wk1)
Stock_Left_WK2 = ( (Stock_Left_WK1 - orders_for_wk2) + (Production.ProduceWk1) )
Stock_Left_WK3 = ( (Stock_Left_WK2 - orders_for_wk3) + (Production.ProduceWk2) )
Stock_Left_WK4 = ( (Stock_Left_WK3 - orders_for_wk4) + (Production.ProduceWk3) )
Please can someone help me? Really stuck on this one!
If you need me to try and explain some more don't hesitate to ask.
Thanks for any help whatsoever.
Paul