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: Easy SQL question

Re: Easy SQL question

From: Tommy Hagström <tomhag_at_rsv.se>
Date: 1998/11/30
Message-ID: <Pine.HPX.4.05.9811301347320.28482-100000@u30040.rsv.svskt.se>#1/1

On Sun, 29 Nov 1998 wbailey_at_my-dejanews.com wrote:

> Forgive my lack of SQL knowledge, but I can't figure this query out....
>
> I have a table x with the following fields: Name, Age, Weight and Date. Each
> time a person is weighed, the record is not replaced, but just versioned by
> adding a new record with the same name, current age and new weight & date.
> What I need to do is, given a person's name, query the table to get the most
> recent weighing for each age. eg:
> Name Age Weight Date
> ---------------------------
> Joe 12 110 10/10/90
> Joe 13 130 12/23/91
> ...
>
> I can figure out how to retun the most recent weighing given the name, but I'm
> stuck on doing it for each age... any ideas?
>
> Thanks for the help,
> Bill
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
>
>

try this one:

select x.weight
  from table x
 where x.date =

      (select max(y.date)
         from table y
        where y.name = x.name
          and y.age = x.age)


tomhag_at_rsv.se Received on Mon Nov 30 1998 - 00:00:00 CST

Original text of this message

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