Is there a way to automate this sort of thing in SQL:
difference between rows 01 and 02 = 100
difference between rows 02 and 03 = 100
difference between rows 03 and 04 = 150
difference between rows 04 and 05 = 50
difference between rows 05 and 06 = 90
difference between rows 06 and 07 = 110
etc…
And end up with a set of data points like:
100
100
150
50
90
110
r1 and r2 are aliasses. They are needed because you’re joining a table to itself, and mysql needs to know where the columns come from you use in the query. Without them, you’d get an error saying that the column name is specified multiple times.
So the r1.field1 construct indicates the column field1 from the table table1 that you’ve given the alias r1.