Re: SQL Help: Multiple LEFT OUTER JOINs

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Bill Moseley <moseley(at)hank(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Help: Multiple LEFT OUTER JOINs
Date: 2005-11-21 17:45:34
Message-ID: 20051121174534.GA24401@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Nov 21, 2005 at 05:40:10 -0800,
Bill Moseley <moseley(at)hank(dot)org> wrote:
>
> Here's where I'm missing something. Trying to do an outer join on
> to bring in the class row with its class_time column:

You don't say exactly why you are having a problem with this, but I think you
would be better off doing an inner join between instructors and class and
then do an outer join of that result to person.

>
>
> SELECT person.id AS id, last_name,
> count(instructors.class) as total,
> sum (CASE WHEN class_time > now() THEN 1 ELSE 0 END) as future_class_count,
> sum (CASE WHEN class_time <= now() THEN 1 ELSE 0 END) as past_class_count
>
>
> FROM (person LEFT OUTER JOIN instructors ON (person.id = instructors.person)) t
> LEFT OUTER JOIN class on ( t.class = class.id ),
> person_role
>
> WHERE person_role.person = person.id
> AND person_role.role = 3
>
> GROUP BY person.id, last_name;
>
>
>
>
>
> --
> Bill Moseley
> moseley(at)hank(dot)org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gary Horton 2005-11-21 18:01:35 Trouble downloading Postgres
Previous Message Berend Tober 2005-11-21 17:34:17 Re: Multi-parameter aggregates.