Консультации по проектированию базы данных инвентаризации
I have a question about inventory project database design Instead of creating a [ProductBalance] column in products table, I left the balance undefined and created another table [Log] Log_ID || Product_ID || OperationType_ID || Input || Output 1 29 1 (Purchases) 5 0 2 24 4 (Sales) 0 2 3 24 5 (SaleReturn) 1 0 * OperationType_ID is related to another table[OperationTypes] Now when user select some product the query will SUM(Input) - SUM(Output) for this product to get the current balance.
Что я уже пробовал:
This worked well till now, but i want to know is this design is bad? For example when i wanted to get total sales and saleReturn for products i tried this: SELECT SUM(A.Output) AS Sales, SUM(B.Input) AS SaleReturn FROM (SELECT * from Log WHERE Log.OperationType_ID = 2) A FULL JOIN (SELECT * FROM Log WHERE Log.OperationType_ID = 5) B ON A.Stock_ID = B.Stock_ID