| From: | John Fabiani <johnf(at)jfcomputer(dot)com> |
|---|---|
| To: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
| Subject: | using the aggregate function max() |
| Date: | 2011-09-23 02:49:20 |
| Message-ID: | 201109221949.20671.johnf@jfcomputer.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Hi,
I need a little help understanding how to attack this problem.
I need to find the max(date) of a field but I need that value later in my
query.
If I
select max(x.date_field) as special_date from (select date_field) from table
where ...)x
I get one row and column.
But now I want to use that field in the rest of the query
select y.*, max(x.date_field) as special_date from (select date_field) from
table where ...)x
from aTable y where y.somefield = special_date.
The above only returns one row and one column the "special_date."
How can I use the aggregate field "special_date" in the rest of the query? Or
is there some other way?
Johnf
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David Johnston | 2011-09-23 03:14:58 | Re: using the aggregate function max() |
| Previous Message | Brian Sherwood | 2011-09-22 15:03:53 | help with xpath namespace |