1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| select a.consumable_nomination
, (b.SumInput - c.SumOutput) as stock
, ( (SUB1.MaxPr/d.stock_movement_quantity)
*(b.SumInput - c.SumOutput)) as 'valeur stock'
, (d.stock_movement_unit_price/d.stock_movement_quantity) as 'prix achat'
From consumable a
join _entry_conso b
on b.id_consumable=a.id_consumable
join _exit_conso c
on c.id_consumable=a.id_consumable
join consumable_stock_movement e
on b.id_consumable=e.id_consumable
join stock_movement d
on d.id_stock_movement=e.id_stock_movement
-- valorisation du stock
inner join(select max(SM.stock_movement_unit_price) as MaxPr
, CM.id_consumable
from stock_movement SM
inner join consumable_stock_movement CM
on CM.id_stock_movement=SM.id_stock_movement
group by CM.id_consumable) SUB1
--
where b.SumInput - c.SumOutput > 0
and d.stock_movement_quantity<>0
group by e.id_consumable
, a.consumable_nomination
, a.consumable_nomination
, a.consumable_name
, (d.stock_movement_unit_price/d.stock_movement_quantity)
, (b.SumInput - c.SumOutput)
, (d.stock_movement_unit_price*(b.SumInput - c.SumOutput)) |
Partager