Re: Count the children

Поиск
Список
Период
Сортировка
От Mark Styles
Тема Re: Count the children
Дата
Msg-id 20090818144400.GD28516@lambic.co.uk
обсуждение исходный текст
Ответ на Count the children  (Michael Rowan <mike.rowan@internode.on.net>)
Ответы Re: Count the children  (Michael Rowan <mike.rowan@internode.on.net>)
Список pgsql-novice
On Wed, Aug 19, 2009 at 12:04:13AM +0930, Michael Rowan wrote:
> I need what sounds like a very simple query - but I'm darned if I can
> figure it out.
>
> I have two tables, parent and child related by child.parent_id =
> parent.id
> The query should return, for each parent row, parent.name and number of
> child rows
>
> Can someone enlighten me, please?

Assuming parent.name is unique:

SELECT parent.name, count(*)
FROM   parent, child
WHERE  parent.key = child.parent_key
GROUP BY parent.name;

--
Mark
http://www.lambic.co.uk


Вложения

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

Предыдущее
От: Sean Davis
Дата:
Сообщение: Re: Count the children
Следующее
От: Sean Davis
Дата:
Сообщение: Re: Count the children