var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Using Next and Previous in MySQL
I am pretty new to MySQL. We are using MySQL 4.1.5 to write queries and incorporate them into Crystal Reports.
Is there a 'Next' or 'Previous' function in MySQL? I have not found anything. I have a table like the following:
Date1 | Date2 | Value
02/01/06 | 01/15/06 | 35
02/01/06 | 01/20/06 | 38
02/01/06 | 03/20/06 | 41
What I need is (using the second line as an example):
If (Date2 < Date1) Then MyAnswer = Previous(Value) = 35.
How do I write a query statement to get the previous value?
Can this be done using stored procedures?
Thanks in advance.
If you're just trying to return that one value, you could try using the LIMIT clause with an offset:
SELECT Value FROM Table WHERE Date2 < Date1 ORDER BY Date2 DESC LIMIT 1,1
Thanks for that answer. It works for the single value, however, I will need to return more than one value. So, any other ideas?
how do you define "previous"? the rows in a database table have no physical order