From: | Andy Colson <andy(at)squeakycode(dot)net> |
---|---|
To: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: sql help, reusing a column |
Date: | 2010-04-29 22:02:26 |
Message-ID: | 4BDA01F2.8010608@squeakycode.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 4/29/2010 4:51 PM, Andy Colson wrote:
> 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
>
Ahh, shoot, it was the idate in the order by, not the select list. Both
"order by 3" and "order by max(idate)" work just fine.
Sorry for the noise... but still... I'm kinda curious, in my first
example, how you can re-use a column. Is there a way to:
select organization, state,
(select max(idate) from times where customers.custid=times.custid and
taskid = 27) as lastdate,
age(lastdate)
from customers
-Andy
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Kellerer | 2010-04-29 22:08:52 | Re: sql help, reusing a column |
Previous Message | Andy Colson | 2010-04-29 21:51:50 | sql help, reusing a column |