I have a mysql database with four columns: date, time when gotten up, time when gone to bed and hours slept. Everyday, the date and both times are entered via an html form using php. My goal is to automatically calculate the hours slept and insert them using only the database. I have implemented something similar like this with DOUBLE AS
in the past but the problem in my current case is that I need the bedtime from the day / row before to do this.
So my question is this: In mysql (or another rdbms), is there a way to calculate the difference of two values which belong to different columns and different rows of a table whenever a new row is inserted?