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.
In reply to OT: peak values with SQL by revdiablo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |