From: | T E Schmitz <mailreg(at)numerixtechnology(dot)de> |
---|---|
To: | William Leite Araújo <william(dot)bh(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: join table with itself? |
Date: | 2007-03-15 18:54:45 |
Message-ID: | 45F99675.5050801@numerixtechnology.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
William Leite Araújo wrote:
> On 15/03/07, *T E Schmitz* <mailreg(at)numerixtechnology(dot)de
> <mailto:mailreg(at)numerixtechnology(dot)de>> wrote:
> (...)
>
> Try join the tables.
>
> SELECT present.day, present.low, (MIN(future.day)-present.day) as
>
> days2fall FROM history AS present JOIN history AS future ON (
> present.day < future.day AND
> future.low <= present.low )
> GROUP BY present.day,present.low
> ORDER BY days2fall DESC
That produces the same result as my previous example but maybe the join
is more efficient, Thank you for the suggestion.
However, I am still stuck as to how to retrieve HIGHEST. The result set
produced by the above query only contains those tuples whose LOW is
lower than present.LOW.
For HIGHEST, I need to look at the rows between present.day and DAYS2FALL:
something like
SELECT MAX (high) from history WHERE day >= present.day AND day <
(present.day + days2fall)
-
Regards,
Tarlika Elisabeth Schmitz
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2007-03-15 20:20:34 | Re: [SQL] PostgreSQL to Oracle |
Previous Message | Scott Marlowe | 2007-03-15 16:13:18 | Re: Alter Table |