pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: negora <negora@negora.com>
To: pgsql-sql@postgresql.org
Subject: Re: all the table values equal
Date: Tue, 21 Sep 2010 10:17:07 +0200
Message-ID: <4C986A03.4030403@negora.com> (raw)
In-Reply-To: <4C9868AB.6050200@unipex.it>
References: <4C93803A.4080706@unipex.it>
	<438B32316EF6496D9641819BA16447A2@marktestcr.marktest.pt>
	<4C938D09.3050105@unipex.it>
	<81C545E3469E4DF58720C282A469E78A@marktestcr.marktest.pt>
	<4C9868AB.6050200@unipex.it>

<!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.6050200@unipex.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.petrazzo@unipex.it">&lt;michele.petrazzo@unipex.it&gt;</a> To: "Oliveiros d'Azevedo Cristina"
    <br>
<a class="moz-txt-link-rfc2396E" href="mailto:oliveiros.cristina@marktest.pt">&lt;oliveiros.cristina@marktest.pt&gt;</a> Cc:
<a class="moz-txt-link-rfc2396E" href="mailto:pgsql-sql@postgresql.org">&lt;pgsql-sql@postgresql.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@postgresql.org">pgsql-sql@postgresql.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<...;
      <br>
    </blockquote>
    <br>
    <br>
  </blockquote>
  <br>
  <br>
  <br>
</blockquote>
</body>
</html>



view thread (10+ messages)  latest in thread

Message-ID: <4C986A03.4030403@negora.com>
Permalink:  ../4C986A03.4030403@negora.com/
Also on:    postgresql.org/message-id/4C986A03.4030403@negora.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: negora@negora.com
  Subject: Re: all the table values equal
  In-Reply-To: <4C986A03.4030403@negora.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox