Help please understand the creation of views ...
There is a sign with numbers for each day:
+------------+-------+ | date | value | +------------+-------+ | 2018-02-10 | 5 | | 2018-02-11 | 2 | | 2018-02-12 | 3 | | 2018-02-13 | 1 | | 2018-02-14 | 7 | +------------+-------+ There is another label initial value: 100.
We need a view that will count the remainder.
Example. 2018-02-09 there were 100pcs of goods. every day is written off.
The presentation should show a balance for each day.
As a result, get:
+------------+-------+ | date | rest | +------------+-------+ | 2018-02-10 | 95 | | 2018-02-11 | 93 | | 2018-02-12 | 90 | | 2018-02-13 | 89 | | 2018-02-14 | 82 | +------------+-------+ As I understand it, for the first line you need to make the difference of the "Initial quantity" field and the first day, and for the rest, make the difference of what happened in the presentation in the previous line and the loss per day.
Here is the beginning of the query that we managed to write:
select `ks`.`Date` AS `Date`,if((`ks`.`Id` = '1'),(`hc`.`HС` - `ks`.`HC`),'0') AS `HC` from ((`CS`.`KH` `ks` join `CS`.`Users` `hc`) where (`hc`.`TableName` = 'K')