Re: Select Rows With Only One of Two Values

Поиск
Список
Период
Сортировка
От Chris Angelico
Тема Re: Select Rows With Only One of Two Values
Дата
Msg-id CAPTjJmqXe_WwTmpD32iszrUQM_Jo=astANrOSBqbhapb8WcUxw@mail.gmail.com
обсуждение исходный текст
Ответ на Select Rows With Only One of Two Values  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: Select Rows With Only One of Two Values [RESOLVED]
Re: Select Rows With Only One of Two Values
Список pgsql-general
On Sat, Jul 21, 2012 at 1:53 AM, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>   The table has a Boolean indicator column with values of 0 or 1 for each
> row in the table and another attribute column for parameter names. I need to
> find all parameter names where the indicator value is only 0 for all rows of
> that parameter. At least some of the parameters have both rows with 0 and
> rows with 1 in the indicator attribute. I want to find all (any?) that have
> only zeros.

Try this:

SELECT DISTINCT param FROM table WHERE indicator=0
EXCEPT
SELECT DISTINCT param FROM table WHERE indicator=1

You'll get a list of rows with indicator 0, and then remove from that
list any that are also found in the second query. What's left is the
rows that have only indicator 0.

Chris Angelico

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