Re: Dumb question about count()

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Dumb question about count()
Дата
Msg-id 20050722053507.GA13925@winnie.fuhr.org
обсуждение исходный текст
Ответ на Dumb question about count()  (Benjamin Smith <lists@benjamindsmith.com>)
Список pgsql-general
On Thu, Jul 21, 2005 at 10:09:07PM -0700, Benjamin Smith wrote:
> select classroom.title,
>     count(students.id) AS students,
>     count(seats.id) AS seats
> from classrooms, students, seats
> where classrooms.id=students.classrooms_id
> and classrooms.id=seats.id
>
> Except that it counts 0s for seats/students.
>
> Why can't I recall/find how to do this particular join?

Sounds like you're looking for an outer join.

http://www.postgresql.org/docs/8.0/static/tutorial-join.html
http://www.postgresql.org/docs/8.0/static/queries-table-expressions.html#QUERIES-FROM

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Strange input/cast semantics for inet
Следующее
От: "Rose, Juergen"
Дата:
Сообщение: Re: Insert into ... Select ... From ... too intelligent transaction