Re: What can I use as a [non-aggregate] minimum function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: What can I use as a [non-aggregate] minimum function
Дата
Msg-id 28156.1008025622@sss.pgh.pa.us
обсуждение исходный текст
Ответ на What can I use as a [non-aggregate] minimum function  ("Paul Wehr" <postgresql@industrialsoftworks.com>)
Ответы Re: What can I use as a [non-aggregate] minimum function  ("Paul Wehr" <postgresql@industrialsoftworks.com>)
best solution for BLOB storage across networks?  (Terrence Brannon <metaperl@mac.com>)
Список pgsql-general
"=?iso-8859-1?Q?Paul_Wehr?=" <postgresql@industrialsoftworks.com> writes:
> I need to find the minimum of dates in a number of tables, but "min(date)"
> is, of course, an aggregate function.  For example:

> select key, min(a.date, b.date, c.date) as first_date
> from table_a a, table_b b, table_c c
> where a.key=b.key and a.key=c.key

Does that really express the computation you want, ie produce a result
only for key values that occur in all three tables?

I was going to suggest

select key, min(date) as first_date from
(select key, date from table_a
 union all
 select key, date from table_b
 union all
 select key, date from table_c) subsel
group by key;

but it occurs to me that this produces different results, ie, it will
include key values that only occur in one or two of the tables ...

            regards, tom lane

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

Предыдущее
От: Glen Eustace
Дата:
Сообщение: Re: Weird problem - possibly a bug.
Следующее
От: Andrew Gould
Дата:
Сообщение: Re: Need SQL help, I'm stuck.