Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1B9F99FBD56 for ; Thu, 15 Mar 2007 12:57:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 44531-01-5 for ; Thu, 15 Mar 2007 12:57:06 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.238]) by postgresql.org (Postfix) with ESMTP id 858799FBD75 for ; Thu, 15 Mar 2007 12:57:07 -0300 (ADT) Received: by wx-out-0506.google.com with SMTP id i28so221754wxd for ; Thu, 15 Mar 2007 08:57:06 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=DLGYmkXKYI9QxYX/vR7x2ApExKSA4OpkFj+5gxmQu/m9JmUnrhV3Z4qFiOvnr15WW65z8judd7p1JxEsr1NmfEE4lW33Wourywd6nywL7vgsEnj8AuMM1uhVc3VJLwSVobIX9ug2vn47sgb0fWltXpHygM2WC0O2/MjvoSKLfGE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=OIlJSAcX+rfLXg0+0BwXU3WArbRpceyZ+bWSUrYQwJ/900/Fx0xb+UuwF7Eo0g65Im18xSEGJxqR1r1Fsjg5EC9zGo22JMIuO90CHw0tIZWB88qC3kc8Rf8F+6XT39OHWJJ93sPbRP2QA+kxG3s9Clsy9pJZ3SdZRXQ3oetYH7w= Received: by 10.90.89.5 with SMTP id m5mr638769agb.1173974226497; Thu, 15 Mar 2007 08:57:06 -0700 (PDT) Received: by 10.90.96.15 with HTTP; Thu, 15 Mar 2007 08:57:06 -0700 (PDT) Message-ID: Date: Thu, 15 Mar 2007 12:57:06 -0300 From: "=?ISO-8859-1?Q?William_Leite_Ara=FAjo?=" To: pgsql-sql@postgresql.org Subject: Re: join table with itself? In-Reply-To: <45F96A04.7020307@numerixtechnology.de> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_42813_20047304.1173974226448" References: <45F96A04.7020307@numerixtechnology.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/214 X-Sequence-Number: 27852 ------=_Part_42813_20047304.1173974226448 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 15/03/07, T E Schmitz 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 <=3D present.low ) > GROUP BY present.day,present.low > ORDER BY days2fall DESC --=20 William Leite Ara=FAjo Analista de Banco de Dados - QualiConsult ------=_Part_42813_20047304.1173974226448 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 15/03/07, T E Schmitz <mailreg@numerixtechnology.de> wr= ote:
(...)
 
 &= nbsp; Try join the tables.

SEL= ECT  present.day, present.low, (MIN(future.day)-present.day) as <= br>
days2fall FROM hi= story AS present = JOIN history AS future ON ( present.day < future.day AND
   &= nbsp; future.low <=3D present.low )
GROUP BY present.day,present.low
ORDER BY days2fall DESC


--
William Leite Ara=FAjo
Analista de Banc= o de Dados - QualiConsult ------=_Part_42813_20047304.1173974226448--