I have a table with some statistics, that looks like this after selecting and grouping:
SELECT * FROM Statistics WHERE id IN (
select max(id) id
from Statistics
group by DAY(Statistics.Datetime_Scan)
)
ID Datetime_Scan Count
2 4/6/2017 302
10 4/7/2017 391
18 4/8/2017 500
26 4/9/2017 605
34 4/10/2017 725
42 4/11/2017 832
I would like to add a new column with the delta number, that will show the daily increase/decrease in Count. Like the table below:
ID Datetime_Scan Count Delta
2 4/6/2017 302 0
10 4/7/2017 391 89
18 4/8/2017 500 109
[...]
Should I do a kind of loop in MySQL and calculate the delta with the previous day from each date? Thanks.