Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 1CBEBB5DC61 for ; Sun, 23 Oct 2011 19:57:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 59322-06 for ; Sun, 23 Oct 2011 22:57:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from u1.diff.org (u1.diff.org [78.46.96.43]) by mail.postgresql.org (Postfix) with ESMTP id 8BE16B5D803 for ; Sun, 23 Oct 2011 19:57:00 -0300 (ADT) Received: from lap.diff.org (vola.diff.org [81.174.26.135]) (authenticated bits=0) by u1.diff.org (8.14.4/8.14.4) with ESMTP id p9NMuu8L032268 for ; Sun, 23 Oct 2011 22:56:59 GMT (envelope-from nonsolosoft@diff.org) Message-ID: <4EA49B58.9040602@diff.org> Date: Mon, 24 Oct 2011 00:55:20 +0200 From: Ferruccio Zamuner Organization: NonSoLoSoft User-Agent: Mozilla/5.0 (X11; U; DragonFly i386; en-US; rv:1.9.2.9) Gecko/20101023 Lightning/1.0b3pre Lanikai/3.1.3 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: To having or not to having? References: <4EA4834E.7030409@diff.org> In-Reply-To: <4EA4834E.7030409@diff.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.3.5 (u1.diff.org [78.46.96.43]); Sun, 23 Oct 2011 22:56:59 +0000 (UTC) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201110/59 X-Sequence-Number: 35943 On 10/23/11 23:12, I wrote: > Hello, > > I'm rusty with SQL and I've started to practice it again but I'm falling > on this issue. I've found first solution using WINDOWING: SELECT d.pintime, d.a_id, d.c_id, d.value, d.id, d.sincedate, d.todate, d.description, d.genre FROM (SELECT pintime,a_id,c_id,value,id,sincedate,todate,description, genre, $1::date-a.sincedate as days, min($1::date-a.sincedate) over w AS "days 2" FROM b, a WHERE pintime BETWEEN $2 AND $2::interval+'00:01:00'::interval AND b.a_id=a.id AND a.genre='F' AND description ~*'35$' WINDOW W AS (partition by c_id) ORDER BY $1::date-a.sincedate ASC) AS d WHERE d.days=d."days 2" ORDER BY d.c_id; I'm sure that there are many other solutions and probably mine could be not the best. So I'm looking for more hint and suggestions. Thank you again. \ferz