Jasmin, Thursday, May 02, 2002, 5:00:14 PM, you wrote: JB> I have been trying to use 'user variables' to keep JB> track of the previous row for use in a calculation of JB> the present row. Is there a way I can do this? Or JB> is there a better way in trying to use a previous JB> rows value in the present row.
JB> For example; JB> SELECT number as current_day, (number - <prevnumber>) JB> as change_from_prev_day FROM TABLE ORDER BY DATE JB> <prevnumber> is the reference that I need from the JB> previous row. JB> Am I missing something simple or do I have to do this JB> outside of MYSQL? You can do something like that: SELECT @a:=0; SELECT (number-@a) AS change_from_prev_day, @a:=number FROM your_table; Note: you should set value to variable _after_ calculation. You can find more info about user variables at: http://www.mysql.com/doc/V/a/Variables.html http://www.mysql.com/doc/e/x/example-user-variables.html JB> Any help would be appreciated. thanks, jasmin. -- For technical support contracts, goto https://order.mysql.com/ This email is sponsored by Ensita.net http://www.ensita.net/ __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Victoria Reznichenko / /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED] /_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net <___/ www.mysql.com --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php