view - mysql subtract row by row -
i have 2 mysql (5.6) views. 1 view contains 1 value in 1 row on column. let's column , in single row have value 5000.
i have second view 3 columns: item (varchar), date (obviously containing dates) , value (decimal). second view has 4 rows looks this:
item date value 'lectii de pian', '2015-11-09', '101.88' 'microsoft office','2015-11-11', '7.00' 'belasting', '2015-11-15', '524.00' 'netflix', '2015-11-18', '8.99'
what want create in view column let's call "b" , subtract first value in column value value in view , result subtract next value , on looks this
item date value b 'lectii de pian', '2015-11-09', '101.88' '4898.12' 'microsoft office','2015-11-11', '7.00' '4891.12' 'belasting', '2015-11-15', '524.00' '4367.12' 'netflix', '2015-11-18', '8.99' '4358.13'
any ideas how achieve in mysql 5.6?
many thanks!
use @variable
hold running subtraction, initializing view a.
select b.item, b.date, b.value, @running := @running - value b view2 b cross join (select @running := view1) order b.date
Comments
Post a Comment