Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL query question

Re: SQL query question

From: abc <abc_at_abc.com.au>
Date: Wed, 16 Apr 2003 08:36:05 +1000
Message-ID: <b7i1h0$iuo$1@mws-stat-syd.cdn.telstra.com.au>


Another solution is to use dense_rank if you have Oracle 8i upwards.

select city, rate, efct_date from
(
select city, rate, efct_date, dense_rank() over(partition by City order by Efct_date desc) as date_rank
from rates)
where date_rank = 1;

"Sybrand Bakker" <gooiditweg_at_sybrandb.demon.nl> wrote in message
news:36oo9v4cnmb591j48p5o6g0pd4a8fqe3bl_at_4ax.com...

> On 15 Apr 2003 11:49:14 -0800, yf110_at_vtn1.victoria.tc.ca (Malcolm
> Dew-Jones) wrote:
>
> >Two queries. First gets the right city/date combo, and second uses that
> >information to "index" into the whole table to get the complete data.
> >
> >untested
> >
> > SELECT *
> > FROM rates R
> > WHERE
> > R.CITY||'xxx'||R.efct_date IN
> > ( SELECT I.city || 'xxx' || max(I.efct_date)
> > FROM rates I
> > GROUP BY I.city
> > )
>
>
> awful solution which also won't perform in a real world situation
>
> Better
> select *
> from rates r
> where efct_date =
> (select max(efct_date)
> from rates r1
> where r1.city = r.city
> )
>
>
> Sybrand Bakker, Senior Oracle DBA
>
> To reply remove -verwijderdit from my e-mail address
Received on Tue Apr 15 2003 - 17:36:05 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US