views:

27

answers:

2

Hi everyone,

I have an Oracle 10g table that contains a # of log records. This table collects data from an environmental recording device that creates a log record every 15 seconds when it is running.

I want to add all of the seconds together from the reading dates of the log file entries to ensure that the logger ran > 24 hours (84,600 seconds). The data looks like this:

ID     READING_DATE 
286294 8/4/2010 1:03:30 PM 
286295 8/4/2010 1:03:45 PM 
286296 8/4/2010 1:04:00 PM 
286297 8/4/2010 1:04:15 PM 
286298 8/4/2010 1:04:30 PM 
286299 8/4/2010 1:04:45 PM 
286300 8/4/2010 1:05:00 PM 

I can't just query for the (end date - begin date), because the device may not run 24 hours consecutively. It may run for a total 24 hours over a period of 90 days.

What I want to do is write a query to be executed by the database that add each 15 second interval to the last to see if I have a result that is greater than > 84600.

Any/all replies are appreciated! Thanks in advance,

+3  A: 

The number of seconds that the device has been running is approximately:

SELECT COUNT(*) * 15
FROM your_table
Mark Byers
+1: The OP was really overthinking this one
OMG Ponies
Unfortunately, there are a number of different devices that collect this type of data, and they all sample at different intervals. I don't have any prior knowledge of what the sample rate is for each device type.
Griff
@Griff: You could probably guess the sample rate by looking at the first two rows and calculating the difference. It could give the wrong result in some cases though so be careful. Another alternative is to find the minimum difference between two consecutive rows and use that as the sample rate.
Mark Byers
I think that's what I'll have to do. Hopefully the sample rate doesn't change for the run.
Griff
A: 

Assuming you have multiple devices logged to that table and you want to list all devices that have been running for > 1 day.

SELECT device_id
FROM log_table
GROUP BY device_id
HAVING MAX(reading_date) - MIN(reading_date) > 1.0
Scott Bailey