sql help, reusing a column

Поиск
Список
Период
Сортировка
От Andy Colson
Тема sql help, reusing a column
Дата
Msg-id 4BD9FF76.2010200@squeakycode.net
обсуждение исходный текст
Ответы Re: sql help, reusing a column  (Andy Colson <andy@squeakycode.net>)
Re: sql help, reusing a column  (Thomas Kellerer <spam_eater@gmx.net>)
Список pgsql-general
Here is my query, which works:


select organization,
   state,
   (select max(idate) from times where customers.custid=times.custid and
taskid = 27) as lastdate,
   age( (select max(idate) from times where
customers.custid=times.custid and taskid = 27) )
from customers
order by lastdate desc nulls last;


I'd love to use age(lastdate) instead of age( (repeat sql) ), but it
does not seem to work.

I tried this:

select organization, state, max(idate), age(max(idate))
from customers
inner join times using(custid)
where taskid = 27
group by organization, state
order by idate desc nulls last;


but get error that times.idate must appear in group by or used in agg
func... except it is used in an agg func.


Any hints on what I'm missing?

Thanks,

-Andy

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

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: Recovering Data from a crashed database
Следующее
От: Andy Colson
Дата:
Сообщение: Re: sql help, reusing a column