Re: all the table values equal

From: negora <negora(at)negora(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: all the table values equal
Date: 2010-09-21 08:17:07
Message-ID: 4C986A03.4030403@negora.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Verdana">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.<br>
<br>
<br>
</font><br>
On 21/09/10 10:11, Michele Petrazzo - Unipex wrote:
<blockquote cite="mid:4C9868AB(dot)6050200(at)unipex(dot)it" type="cite">Oliveiros
d'Azevedo Cristina ha scritto:
<br>
<blockquote type="cite">Hello again, Michele,
<br>
<br>
</blockquote>
<br>
Ciao,
<br>
<br>
<blockquote type="cite">I haven't open my mailbox during weekend so I
couldn't follow up your
<br>
question.
<br>
<br>
</blockquote>
<br>
No problem!
<br>
<br>
<blockquote type="cite">It would help if you explain a little better
the background of the
<br>
problem you're trying to solve.
<br>
<br>
You want to find all the user IDs which have the same value on a
<br>
given time interval?
<br>
<br>
Is my understanding correct?
<br>
<br>
</blockquote>
<br>
Yes.
<br>
<br>
Re-reading my post I saw that I could explain better!
<br>
<br>
id_user | value | datetime
<br>
1 | 1 | xxx
<br>
1 | 2 | xxx+1
<br>
1 | -1 | xxx+2
<br>
2 | -1 | xxx
<br>
2 | -1 | xxx+1
<br>
3 | 4 | xxx
<br>
3 | 10 | xxx+1
<br>
3 | 4 | xxx+2
<br>
4 | 3 | xxx
<br>
4 | 3 | xxx+1
<br>
<br>
So, the new question: how I can find which id_user has _all_ the
"value"
<br>
that I'm looking for? Say -1 as 3 and I want a id_user=2 for the first
<br>
and for the latter id_user=4
<br>
<br>
<br>
Thanks,
<br>
Michele
<br>
<br>
<blockquote type="cite">Best, Oliver
<br>
<br>
----- Original Message ----- From: "Michele Petrazzo - Unipex"
<br>
<a class="moz-txt-link-rfc2396E" href="mailto:michele(dot)petrazzo(at)unipex(dot)it">&lt;michele(dot)petrazzo(at)unipex(dot)it&gt;</a> To: "Oliveiros d'Azevedo Cristina"
<br>
<a class="moz-txt-link-rfc2396E" href="mailto:oliveiros(dot)cristina(at)marktest(dot)pt">&lt;oliveiros(dot)cristina(at)marktest(dot)pt&gt;</a> Cc:
<a class="moz-txt-link-rfc2396E" href="mailto:pgsql-sql(at)postgresql(dot)org">&lt;pgsql-sql(at)postgresql(dot)org&gt;</a> Sent:
<br>
Friday, September 17, 2010 4:45 PM Subject: Re: [SQL] all the table
<br>
values equal
<br>
<br>
<br>
<blockquote type="cite">Oliveiros d'Azevedo Cristina ha scritto:
<br>
<blockquote type="cite">Howdy , Michele,
<br>
<br>
Give this a try
<br>
<br>
SELECT id_user FROM t_your_table WHERE datetime BETWEEN A --
<br>
plug here beginning of interval AND B -- and end here GROUP BY
<br>
id_user HAVING COUNT(*) = -SUM(value)
<br>
<br>
Then tell me if it gives you what you want
<br>
</blockquote>
<br>
<br>
Thanks, it works, but... it's really a trickle that exploits the
<br>
value -1 if I understand how its work. If there is another value
<br>
where look for? Example 13?
<br>
<br>
Thanks
<br>
<br>
-- Sent via pgsql-sql mailing list (<a class="moz-txt-link-abbreviated" href="mailto:pgsql-sql(at)postgresql(dot)org">pgsql-sql(at)postgresql(dot)org</a>) To
<br>
make changes to your subscription:
<br>
<a class="moz-txt-link-freetext" href="http://www.postgresql.org/mailpref/pgsql-sql">http://www.postgresql.org/mailpref/pgsql-sql</a>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
<br>
<br>
</blockquote>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 3.7 KB

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros d'Azevedo Cristina 2010-09-21 10:25:45 Re: all the table values equal
Previous Message Michele Petrazzo - Unipex 2010-09-21 08:11:23 Re: all the table values equal