Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 2870B9F9B16 for ; Tue, 18 Sep 2007 10:51:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 27616-01 for ; Tue, 18 Sep 2007 10:51:18 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.233]) by postgresql.org (Postfix) with ESMTP id D125F9F95B6 for ; Tue, 18 Sep 2007 10:51:18 -0300 (ADT) Received: by wx-out-0506.google.com with SMTP id r21so1543715wxc for ; Tue, 18 Sep 2007 06:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=pDv1fNGtxWHdOLLGHiZez89fw4fuy2CR+C7XQTdFri0=; b=f1cUG+ifYAOBW16hmnzDhx5YLYqZnrioGeQ/ikl4jPoUN796OdlSYIprgD8X6ad3lnkYUtHL0BidJ1G/slin7HSHUE09QAYAFzlXjUwNalaKFXYz79hDybaiEHmT4u16gbAGDlPmrUMxSzQoPDC64vcSElR+6kVf5QJnP8YyMyQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=OFlQbtG46u/7jJosN3hTaY799A3607xwOjxBb5299fftIkLxT8cNDULs4shQ2NLJF+9b8SvHl0k5aUTIWuANvvDPLFdBnSZiqfDlFXuAo0KzfptJ8FPoQ22ufIskSa7dt6TZlumqHrKrGShm89nfAGqvfi0ZI2PTlcy/6WyQlVQ= Received: by 10.90.81.14 with SMTP id e14mr4221102agb.1190123477255; Tue, 18 Sep 2007 06:51:17 -0700 (PDT) Received: by 10.90.117.8 with HTTP; Tue, 18 Sep 2007 06:51:17 -0700 (PDT) Message-ID: Date: Tue, 18 Sep 2007 08:51:17 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: "Philippe Lang" Subject: Re: Table transform query Cc: pgsql-sql@postgresql.org In-Reply-To: <6C0CF58A187DA5479245E0830AF84F4218CF1F@poweredge.attiksystem.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6C0CF58A187DA5479245E0830AF84F4218CF1F@poweredge.attiksystem.ch> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/131 X-Sequence-Number: 29344 On 9/18/07, Philippe Lang wrote: > ... into this: > > > serial dateL dateR > -------------------- > 1 1 2 > 1 4 > 2 1 2 > 3 1 3 > 4 2 3 > 5 3 SELECT t1.serial, t1.DATE AS datel, t2.DATE AS dater FROM t t1 LEFT JOIN t t2 ON( t1.serial = t2.serial AND t1.DATE < t2.DATE) WHERE t1.delivery = 'L' AND ( t2.delivery = 'R' OR t2.delivery IS NULL) ORDER BY t1.serial