Simulate lag function in MySQL
This is my favorite MySQL hack. This is how you emulate the lag function: SET @quot=-1; select time,company,@quot lag_quote, @quot:=quote curr_quote from stocks order by company,time; lag_quote holds the value of previous row’s quote. For the first row @quot is -1. curr_quote holds the value of current row’s quote. Notes: order by clause is important … Read more