# Thread: calculate difference between rows (was "Sql")

1. Registered User
Join Date
Mar 2004
Posts
128

## Unanswered: calculate difference between rows (was "Sql")

Hi all,
If I have the table:

Date/Time DeviceNumber X
2/12/04 07:15:15 40 20
2/12/04 12:10:02 40 60
2/12/04 17:56:03 40 100
3/12/04 06:12:24 40 500
3/12/04 08:19:15 40 700

How I can calculate the difference of X where the first X was at the minimum time in 3/12/04 and the second X was at the minimum time in 2/12/04.

I mean the two rows:
3/12/04 06:12:24 40 500
2/12/04 07:15:15 40 20

The X difference is: 480

Please help
Thanks...

2. Registered User
Join Date
Aug 2004
Posts
330
Is it me, or does this seem like deja vu.

Try:

Select sum(xx)
from(
select x as xx
from table
where Date/Time = (select max(Date/Time) from table)
union
select multiply(x,-1) as xx
from table
where Date/Time = (select min(Date/Time) from table)
)

The syntax will have to be modified to fit your DBMS and correct any errors i may have included.
Last edited by urquel; 12-03-04 at 11:26.

3. Moderator.
Join Date
Sep 2002
Location
UK
Posts
5,171
Provided Answers: 1
Originally Posted by urquel
Is it me, or does this seem like deja vu.
Yes, this question does seem to be posted on a daily basis at the moment!

4. Resident Curmudgeon
Join Date
Feb 2004
Location
In front of the computer
Posts
15,579
Provided Answers: 54
Originally Posted by urquel
Is it me, or does this seem like deja vu.
As George Carlin put it, "It's not just Deja Vu, it is Deja Vu all over again!"

-PatP

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•