You can use INTERVAL i.e.
Lets say you have a table
mysql> CREATE TABLE foo (bar int(14), fdate date );
Query OK, 0 rows affected (0.27 sec)
mysql> INSERT INTO foo
> VALUES (1, now()),
(25,now() - INTERVAL 1 DAY),
(15,now() - INTERVAL 2 DAY);
mysql> SELECT f1.bar - f2.bar AS diff , f2.fdate
-> FROM foo AS f1
-> INNER JOIN foo AS f2
-> ON (f1.fdate = f2.fdate + INTERVAL 1 DAY);
+------+------------+
| diff | fdate |
+------+------------+
| -24 | 2005-08-15 |
| 10 | 2005-08-14 |
+------+------------+
2 rows in set (0.00 sec)
-----Original Message-----
From: Octavian Rasnita [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 16, 2005 7:51 AM
To: [email protected]; Felix Geerinckx
Subject: Re: query
Hi,
I define the previous record by date. For each record corresponds a date
which is unique and the previous record is that that contains the
yesterday
date.
Thank you.
Teddy
----- Original Message -----
From: "Felix Geerinckx" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, August 16, 2005 2:45 PM
Subject: Re: query
> On 16/08/2005, "Octavian Rasnita" wrote:
>
> > I want to create a query that selects the diference between the
value
> > of a field from the current record and the value of the same field
> > from the previous record.
>
> How do you define "current record" and "previous record"?
> (relational databases are not spreadsheets)
>
> --
> felix
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
>
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]