Wednesday, March 21, 2012

minimum and maximum in a time range (was "SQL query")

Hi all,
If I have the table:

Date/Time X
2/12/2004 07:23:00 100
2/12/2004 07:30:00 200
2/12/2004 09:30:00 500
2/12/2004 14:45:00 600
2/12/2004 15:02:00 100

I want to get X where it's time interval between the minimum time and the maximum time in the period 06:00:00 to 15:15:00
My target to get the minimum X and the maximum X between 06:00:00 and 15:15:00 and substarct them.

Please help
Thanksselect max(x)-min(x)
from some_table
where datetime between timestamp '2004-12-02 06:00:00' and timestamp '2004-12-02 15:15:00';

Of course, specification of dates and times varies from DBMS to DBMS, so the syntax may vary there.

No comments:

Post a Comment