Stock Quantity view in mysql inventory database -


uml diagram

here database design. plan on calculating quantity of components in view subtracting order_linequantity component_usedquantity. problem having surely elementary, current view doesn't work because summing order_linequantities components , likewise component_usedquantities instead of giving proper difference/quantity each individual component.

create view inventory3(componentid, quantity) select distinct(componentid) componentid, sum(order_linequantity) - sum(component_usedquantity) quantity component inner join order_line on order_linecomponentid = componentid inner join component_used on component_usedcomponentid = componentid 

how can proper quantity each individually different componentid?

if use sum() function sum values of table. if want sum related values, have first group values id , sum them. that's below sub query does.

here model of table1- order_line

enter image description here

here model of table2- component_used enter image description here

i have filled necessary details. can see there multiple values of order_linequantity given component.

and multiple values exist component_usedquantity given component.

i have linked using componentid component table.

enter image description here

select componentid componentid,(ordertable.sumorder-componenttable.sumcomponent) quantity  component, (select order_linecomponentid id,sum(order_linequantity) sumorder order_line group order_linecomponentid)ordertable, (select component_usedcomponentid id,sum(component_usedquantity) sumcomponent component_used group component_usedcomponentid)componenttable componentid=ordertable.id , componentid=componenttable.id 

now when execute query, selects required details after grouping operations.

enter image description here


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -