Re: Finding uniques across a big join

Поиск
Список
Период
Сортировка
От John D. Burger
Тема Re: Finding uniques across a big join
Дата
Msg-id 1a8c3e176a2532e639ffe4020c7caabd@mitre.org
обсуждение исходный текст
Ответ на Re: Finding uniques across a big join  (Bruno Wolff III <bruno@wolff.to>)
Ответы Re: Finding uniques across a big join  (Greg Stark <gsstark@mit.edu>)
Список pgsql-general
Bruno Wolff III wrote:

>> That changes the semantics of what I want.  If I group by personID
>> above, then every FOUR-way combo is of course unique.  What I'd like
>> to
>> do is group by the three attributes, and select for personID as well.
>> But of course you can't select for columns you haven't grouped by.
>
> Assuming that personID is an ordered type, you can select max(personID)
> in the GROUP BY and save the join at the end.

I'm not sure what this means - do you mean:

select p2.eyeColor, p2.hairColor, p2.skinColor
   from persons as p2
   group by max(p2.personID), p2.eyeColor, p2.hairColor, p2.skinColor
   having count(*) = 1;

I don't know what that does.  If you mean:

select max(p2.personID), p2.eyeColor, p2.hairColor, p2.skinColor
   from persons as p2
   group by p2.personID, p2.eyeColor, p2.hairColor, p2.skinColor
   having count(*) = 1;

then I don't think that works either - if I include personID in the
GROUP BY, then the COUNT doesn't do what I want, right?  I just want
uniques wrt the three attribute fields.  If I group by personID, then
personID counts towards uniqueness.

Thanks for all the suggestions, folks.

- John Burger
   MITRE


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

Предыдущее
От: William Leite Araújo
Дата:
Сообщение: alter table schema on 8.0.X
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: undefined behaviour for sub-transactions?