I have a table like this (simplified):
+------+--------+
| tick | value |
+------+--------+
| 1 | 10 |
| 2 | 20 |
| 5 | 50 |
| 7 | 10 |
| 10 | 85 |
+------+--------+
I want to generate another table which includes all numbers from min(tick) to max(tick) as tick values:
+------+--------+
| tick | value |
+------+--------+
| 1 | 10 | * already exists
| 2 | 20 | * already exists
| 3 | 30 | = 20 + 10
| 4 | 40 | = 30 + 10
| 5 | 50 | = 40 + 10 * already exists
| 6 | 30 | = 50 - 20
| 7 | 10 | = 30 - 10 * already exists
| 8 | 35 | = 10 + 25
| 9 | 60 | = 35 + 25
| 10 | 85 | = 60 + 25 * already exists
+------+--------+
To be clear,
- I have non-consecutive tick values and want to insert missing ticks.
- I want to do this to another table, so original table won’t be modified.
values of missingticks increases/decreases as equal steps from previous existing tick to next existing tick. As a psudo-formula:
increment = (next_value - current_value) / (next_tick - current_tick)
How to manage this?
This stored procedure will do what you want, populating the table
allticksAdd the initial ticks and values where indicated, they are needed, if there is no row with ticks=1