Re: A select DISTINCT query? - followup Q

Поиск
Список
Период
Сортировка
От Mike Ginsburg
Тема Re: A select DISTINCT query? - followup Q
Дата
Msg-id 479CD3D2.80508@collaborativefusion.com
обсуждение исходный текст
Ответ на Re: A select DISTINCT query? - followup Q  (Phil Rhoades <phil@pricom.com.au>)
Ответы Re: A select DISTINCT query? - followup Q  (johnf <jfabiani@yolo.com>)
Re: A select DISTINCT query? - followup Q  (Phil Rhoades <phil@pricom.com.au>)
Список pgsql-general
Hi Phil,
  Each of columns that you specify in your SELECT clause, must also
appear in the GROPU BY clause.

SELECT COUNT(*) AS cnt, name, comment, ...
FROM tst
GROUP BY name, comment, ...
HAVING COUNT(*) = 1;


Phil Rhoades wrote:
> People,
>
>
>
>> select count(*) as cnt, name from tst group by name having count(*) = 1
>>
>
>
> This worked for my basic example but not for my actual problem - I get
> "column comment must appear in the GROUP BY clause or be used in an
> aggregate function" errors so I have a related question:
>
> With table:
>
> name comment
>
> 1    first comment
> 2    second comment
> 3    third comment
> 3    fourth comment
> 4    fifth comment
> 5    sixth comment
>
> - how can I use something like the previous select statement but where
> the comment field does not appear in the "group by" clause and gives the
> following result:
>
> 1    first comment
> 2    second comment
> 4    fifth comment
> 5    sixth comment
>
> Thanks,
>
> Phil.
>

Mike Ginsburg
Collaborative Fusion, Inc.
mginsburg@collaborativefusion.com
412-422-3463 x4015

--
****************************************************************
IMPORTANT: This message contains confidential information
and is intended only for the individual named. If the reader of
this message is not an intended recipient (or the individual
responsible for the delivery of this message to an intended
recipient), please be advised that any re-use, dissemination,
distribution or copying of this message is prohibited. Please
notify the sender immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The
sender therefore does not accept liability for any errors or
omissions in the contents of this message, which arise as a
result of e-mail transmission.
****************************************************************




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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Very long execution time of "select nextval('..');"
Следующее
От: johnf
Дата:
Сообщение: Re: A select DISTINCT query? - followup Q