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:

  1. The uid is not available in the subselect, and as such I get an error: ERROR:  column "uid" does not exist
  2. I don't know if uid+1 would do what I expected, even if uid was found.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.