Re: all the table values equal

Поиск
Список
Период
Сортировка
От Oliveiros d'Azevedo Cristina
Тема Re: all the table values equal
Дата
Msg-id 438B32316EF6496D9641819BA16447A2@marktestcr.marktest.pt
обсуждение исходный текст
Ответ на all the table values equal  (Michele Petrazzo - Unipex <michele.petrazzo@unipex.it>)
Ответы Re: all the table values equal
Список pgsql-sql
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" <michele.petrazzo@unipex.it>
To: <pgsql-sql@postgresql.org>
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Michele Petrazzo - Unipex
Дата:
Сообщение: all the table values equal
Следующее
От: Michele Petrazzo - Unipex
Дата:
Сообщение: Re: all the table values equal