Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DB8BD1336B42 for ; Tue, 21 Sep 2010 05:24:03 -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 60282-08 for ; Tue, 21 Sep 2010 08:23:57 +0000 (UTC) X-Greylist: delayed 00:06:38.904434 by SQLgrey-1.7.6 Received: from oproxy2-pub.bluehost.com (oproxy2-pub.bluehost.com [67.222.39.60]) by mail.postgresql.org (Postfix) with SMTP id 4462D1337B4A for ; Tue, 21 Sep 2010 05:23:51 -0300 (ADT) Received: (qmail 19492 invoked by uid 0); 21 Sep 2010 08:17:11 -0000 Received: from unknown (HELO box398.bluehost.com) (69.89.31.198) by oproxy2.bluehost.com with SMTP; 21 Sep 2010 08:17:11 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=negora.com; h=Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Identified-User; b=CE57RBgjHdCOIcinGlPTJOAWrlIR+crtSN/PJhmlYTTXy+60xwA+Bv63s8dE61yZiy1jrqdKAPkS4i+C95+si2CD6ZpRyJmaP0XQV/XVJJyQGc/lv0V2scDarq4aJ8qE; Received: from 30.red-80-32-234.staticip.rima-tde.net ([80.32.234.30] helo=[172.16.0.2]) by box398.bluehost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1Oxy2H-0003p7-Uq for pgsql-sql@postgresql.org; Tue, 21 Sep 2010 02:17:10 -0600 Message-ID: <4C986A03.4030403@negora.com> Date: Tue, 21 Sep 2010 10:17:07 +0200 From: negora User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100915 Lightning/1.0b1 Thunderbird/3.0.8 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: all the table values equal References: <4C93803A.4080706@unipex.it> <438B32316EF6496D9641819BA16447A2@marktestcr.marktest.pt> <4C938D09.3050105@unipex.it> <81C545E3469E4DF58720C282A469E78A@marktestcr.marktest.pt> <4C9868AB.6050200@unipex.it> In-Reply-To: <4C9868AB.6050200@unipex.it> Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Identified-User: {2410:box398.bluehost.com:negoraco:negora.com} {sentby:smtp auth 80.32.234.30 authed with negora+negora.com} X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.176 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.723, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201009/61 X-Sequence-Number: 34592 I'm not sure if I understood you right, but it sounds similar to a case which I faced recently. Why not to use an inverse approach? In other words: trying to find those registries which hasn't got at least one value which differs from which you want to look for. How? Using the EXISTS function with some kind of subquery I guess.



On 21/09/10 10:11, Michele Petrazzo - Unipex wrote:
Oliveiros d'Azevedo Cristina ha scritto:
Hello again, Michele,


Ciao,

I haven't open my mailbox during weekend so I couldn't follow up your
question.


No problem!

It would help if you explain a little better the background of the
problem you're trying to solve.

You want to find all the user IDs which have the same value on a
given time interval?

Is my understanding correct?


Yes.

Re-reading my post I saw that I could explain better!

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
3 | 4 | xxx+2
4 | 3 | xxx
4 | 3 | xxx+1

So, the new question: how I can find which id_user has _all_ the "value"
that I'm looking for? Say -1 as 3 and I want a id_user=2 for the first
and for the latter id_user=4


Thanks,
Michele

Best, Oliver

----- Original Message ----- From: "Michele Petrazzo - Unipex"
<michele.petrazzo@unipex.it> To: "Oliveiros d'Azevedo Cristina"
<oliveiros.cristina@marktest.pt> Cc: <pgsql-sql@postgresql.org> Sent:
Friday, September 17, 2010 4:45 PM Subject: Re: [SQL] all the table
values equal


Oliveiros d'Azevedo Cristina ha scritto:
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


Thanks, it works, but... it's really a trickle that exploits the
value -1 if I understand how its work. If there is another value
where look for? Example 13?

Thanks

-- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To
make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql