Re: Conditional left join

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: Conditional left join
Дата
Msg-id CAF-3MvN3=gCbG=A+5MrTdfgJw8VZ-aChw-y-2C5UN-qxQHrYOA@mail.gmail.com
обсуждение исходный текст
Ответ на Conditional left join  (Amitabh Kant <amitabhkant@gmail.com>)
Список pgsql-general
On 1 December 2011 13:16, Amitabh Kant <amitabhkant@gmail.com> wrote:
> I am trying (through conditional left join?) to fetch all records of tbldata
> and the operator name from tbloperators who was operating the unit at event
> time. If no operator was present, it should return null.

I think you want something akin to:

SELECT *
FROM tbldata AS a
LEFT JOIN (tbloperatorschedule INNER JOIN tbloperator USING (operator_id)) AS b
   ON (a.unit_id = b.unit_id AND
       a.event_time BETWEEN b.schedule_start_time AND b.schedule_end_time
        )


--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

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

Предыдущее
От: Amitabh Kant
Дата:
Сообщение: Conditional left join
Следующее
От: Samba
Дата:
Сообщение: Re: How to restore the table space tar files created by pg_basebackup?