Re: extend "group by" to include "empty relations" ?

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: extend "group by" to include "empty relations" ?
Дата
Msg-id 20071213191017.GM6262@alvh.no-ip.org
обсуждение исходный текст
Ответ на extend "group by" to include "empty relations" ?  (peter pilsl <pilsl@goldfisch.at>)
Список pgsql-general
peter pilsl wrote:

> But there is a problem now: There are also entries in fn_kat which dont
> have corresponding entries in fn_dokumente and this entries should be
> listed too. With the proper count=0 !!

Your problem is not on the GROUP BY, but rather that you need an outer
join.  Try something like

 select k.kategorie,count(d.oid) from fn_kat k left join fn_dokumente d
 on k.id=d.kategorie group by k.kategorie;

--
Alvaro Herrera                               http://www.PlanetPostgreSQL.org/
"The first of April is the day we remember what we are
the other 364 days of the year"  (Mark Twain)

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

Предыдущее
От: "Uwe C. Schroeder"
Дата:
Сообщение: Re: For the SQL gurus out there
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: Slow PITR restore