Re: count(*) - join question

Поиск
Список
Период
Сортировка
От Richard Poole
Тема Re: count(*) - join question
Дата
Msg-id 20011127142530.C24565@office.vi.net
обсуждение исходный текст
Ответ на count(*) - join question  ("Nicole S. Weber" <nweber@ic.ac.uk>)
Список pgsql-sql
On Mon, Nov 26, 2001 at 11:03:56PM +0000, Nicole S. Weber wrote:
> 
> I have tried to use a join on the sample_id in combination with
> COUNT(*)/GROUP BY sample_id:
> 
> SELECT animals.sample_id, samples.sample_date, samples.sample_code,
> count(*)
>   FROM animals, samples
>   WHERE samples.sample_id = animals.sample_id
>   GROUP BY animals.sample_id;
> 
> Alas, this returns:
> 
> ERROR:  Attribute samples.sample_Dadate must be GROUPed or used in an
> aggregate function

You need to GROUP BY all the columns that you're not counting the
different occurrences of:

SELECT animals.sample_id, samples.sample_date, samples.sample_code, count(*)
FROM animals, samples
WHERE samples.sample_id = animals.sample_id
GROUP BY animals.sample_id, samples.sample_date, samples.sample_code;

Richard


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

Предыдущее
От: "Nicole S. Weber"
Дата:
Сообщение: count(*) - join question
Следующее
От: "Aasmund Midttun Godal"
Дата:
Сообщение: Re: PL/pgSQL examples NOT involving functions