revdiablo has asked for the wisdom of the Perl Monks concerning the following question:
Sorry for the off-topic question, but maybe someone here will have some ideas for me. I have a table with uptime values, updated once a day. I'd like to know how high the uptime was before each reboot, so I'd like the peak uptime values. This is easily accomplished with some perl code like the following:
my @uptimes = qw(1 2 3 4 5 1 2 3 4 1 2 3 4 5 6); for (0 .. $#uptimes) { print "We have a peak value: $uptimes[$_]\n" if $_ == $#uptimes or $_ < $#uptimes and $uptimes[$_] > $uptimes[$_+1]; }
I'd like to do this all in SQL, however. It's less a practical requirement than idle curiosity, but maybe I'll end up learning something useful. Here's one approach I thought might work:
SELECT uptime_id as uid, uptime_value FROM uptime WHERE uptime_value > (SELECT uptime_value FROM uptime WHERE uptime_id = uid+1);
But there are some problems with this:
For your information, I'm using PostgreSQL. Many of its features are compatible with Oracle, so if you have any ideas that work with Oracle, they might with PostgreSQL.
Any ideas are appreciated.
Update: thanks to Enlil for the suggestion, but the following won't quite do it either:
SELECT MAX(uptime_value) FROM uptime;
This selects the highest uptime, but I want all the peaks, not just the highest one.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OT: peak values with SQL
by runrig (Abbot) on Jun 05, 2004 at 00:08 UTC | |
by revdiablo (Prior) on Jun 05, 2004 at 00:18 UTC | |
|
Re: OT: peak values with SQL
by eclark (Scribe) on Jun 05, 2004 at 01:06 UTC | |
by runrig (Abbot) on Jun 06, 2004 at 18:39 UTC | |
by revdiablo (Prior) on Jun 05, 2004 at 01:28 UTC | |
by runrig (Abbot) on Jun 07, 2004 at 23:08 UTC | |
|
Re: OT: peak values with SQL
by kragen (Sexton) on Jun 05, 2004 at 00:30 UTC | |
|
Re: OT: peak values with SQL
by jZed (Prior) on Jun 05, 2004 at 01:09 UTC | |
|
•Re: OT: peak values with SQL
by merlyn (Sage) on Jun 05, 2004 at 13:12 UTC | |
by jZed (Prior) on Jun 05, 2004 at 17:00 UTC | |
by merlyn (Sage) on Jun 05, 2004 at 22:36 UTC |