php - total inventory stock mysql -
i have follow question question of mine if don't mind..
count total flow inventory in , out php mysql
table ======================================================= **id** | **code** | **status** | **total** | **date** | 1 | b01 | in | 500 |2013-01-15| 2 | b01 | out | 100 |2013-01-20| 3 | b01 | out | 200 |2013-02-01| 4 | b01 | in | 300 |2013-02-05| from table above output this..
table =================================================================================== **id** | **code** | **status** | **total** | **date** | **stock** | 1st month stock 1 | b01 | in | 500 |2013-01-15| 500 | - 2 | b01 | out | 100 |2013-01-20| 400 | 500 3 | b01 | in | 200 |2013-02-01| 600 | 400 4 | b01 | out | 300 |2013-02-05| 300 | 600 5 | | | | | | 300 how can accomplish using mysql ? there way?
for stock column i'm accomplish using method
select t.*, @stock := @stock + case when status = 'in' total else -total end stock your_table t cross bring together (select @stock := 0) s order t.id from previous question, help me i'm new mysql
based on have, add together look select list,
select t.*, @stock `1st month stock`, @stock := ... n.b. homecoming of current value of @stock need come before new value assigned @stock in select list, order of columns different shown in desired output.
based on current query, add together new look select list, homecoming column, e.g.
select t.* , @stock `1st month stock` , @stock := @stock + case when status = 'in' total else -total end stock your_table t cross bring together (select @stock := 0) s order t.id php mysql sql
No comments:
Post a Comment