Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id BCCE11337CDC for ; Fri, 17 Sep 2010 12:03:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 36887-03 for ; Fri, 17 Sep 2010 15:03:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 65D471337BF1 for ; Fri, 17 Sep 2010 12:03:28 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id SBPTY7P6; Fri, 17 Sep 2010 16:03:26 +0100 Message-ID: <438B32316EF6496D9641819BA16447A2@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: "Michele Petrazzo - Unipex" , References: <4C93803A.4080706@unipex.it> Subject: Re: all the table values equal Date: Fri, 17 Sep 2010 16:03:25 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-5 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/49 X-Sequence-Number: 34580 Howdy , Michele, Give this a try SELECT id_user FROM t_your_table WHERE datetime BETWEEN A -- plug here beginning of interval AND B -- and end here GROUP BY id_user HAVING COUNT(*) = -SUM(value) Then tell me if it gives you what you want Best, Oliveiros Cristina ----- Original Message ----- From: "Michele Petrazzo - Unipex" To: Sent: Friday, September 17, 2010 3:50 PM Subject: [SQL] all the table values equal > Hi list, > this is a Friday afternoon question... :) > I have a table like this: > > id_user | value | datetime > 1 | 1 | xxx > 1 | 2 | xxx+1 > 1 | -1 | xxx+2 > 2 | -1 | xxx > 2 | -1 | xxx+1 > 3 | 4 | xxx > 3 | 10 | xxx+1 > > I'm trying to create a query that say me which id_user, inside a > interval of time, has all the values -1 > > The part if the interval it's not a problem, but I'm fighting with the > aggregate... > Someone? > > Thanks, > Michele > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql