Skip site navigation (1) Skip section navigation (2)

Re: sql help, reusing a column

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: sql help, reusing a column
Date: 2010-04-29 22:08:52
Message-ID: hrd01k$qpu$1@dough.gmane.org (view raw or flat)
Thread:
Lists: pgsql-general
Andy Colson wrote on 29.04.2010 23:51:
> 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.

This should work:

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


In response to

Responses

pgsql-general by date

Next:From: Craig RingerDate: 2010-04-29 23:39:09
Subject: Re: Recovering Data from a crashed database
Previous:From: Andy ColsonDate: 2010-04-29 22:02:26
Subject: Re: sql help, reusing a column

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group