Re: selecting coordinates.

From: Steven Seacord <seacords_at_source.asset.com>
Date: 1995/06/09
Message-ID: <3r9pd2$k49_at_source.asset.com>#1/1


In article <eckley-070695085432_at_lurch.jhuapl.edu>, JE <eckley_at_capsrv.jhuapl.edu> wrote:
>I have a simple query that I want to perform, but seem to be
>out of it this week and cannot come up with it.
>
>Assume a table (simplified) as follows:
>
>coordinates
>(
>x integer,
>y integer
>)
>
>If this table is populated with values like
>
>1,1
>1,2
>1,3
>1,4
>2,1
>2,2
>2,3
>2,4
>2,5
>
>How can I use a single select statement to retrieve the following
>results:
>
> 1,5
> 2,5
>
>that is, all unique x coordinates paired with the highest corresponding
>y coordinate?
>

I am not sure if you want to return 1,5 and 2,5 or if you want to return 1,4 and 2,5 (unique x coordinates paired with the highest corresponding y coordinate. Here are two queries for you, one for each.  

Returns 1,5 and 2,5:  

select distinct(a.x), b.y
from coordinates a, coordinates b
where b.y = (select max(c.y) from coordinates c;  

Returns 1,4 and 2,5:  

select x, max(y)
from coordinates
group by x;  

Steven Seacord
Oracle Contractor
Oxford International
seacords_at_source.asset.com



This disclaimer has been disclaimed. Received on Fri Jun 09 1995 - 00:00:00 CEST

Original text of this message