For each key, find row with highest value of other field
For each key, find row with highest value of other field
От:
Raj Mathur <raju@linux-delhi.org>
Дата:
I have some data of the form: Key | Date | Value A | 2008-05-01 | foo * A | 2008-04-01 | bar A | 2008-03-01 | foo * B | 2008-03-04 | baz B | 2008-02-04 | bar C | 2008-06-03 | foo * C | 2008-04-04 | baz C | 2008-03-04 | bar Is there any way to select only the rows marked with a (*) out of these without doing a join? I.e. I wish to find the row with the highest Date for each Key and use the Value from that. Regards, -- Raju -- Raj Mathur raju@kandalaya.org http://kandalaya.org/ GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F PsyTrance & Chill: http://schizoid.in/ || It is the mind that moves
Re: For each key, find row with highest value of other field
От:
"Oliveiros Cristina" <oliveiros.cristina@marktest.pt>
Дата:
Howdy, Raju Do you want somethin like this? Not sure if I fully understood your requests... SELECT "Key",MAX(Date) FROM t_yourTable WHERE Value LIKE 'foo' GROUP BY Key ; Best, Oliveiros ----- Original Message ----- From: "Raj Mathur" To: Sent: Friday, October 03, 2008 7:55 PM Subject: [SQL] For each key, find row with highest value of other field >I have some data of the form: > > Key | Date | Value > A | 2008-05-01 | foo * > A | 2008-04-01 | bar > A | 2008-03-01 | foo * > B | 2008-03-04 | baz > B | 2008-02-04 | bar > C | 2008-06-03 | foo * > C | 2008-04-04 | baz > C | 2008-03-04 | bar > > Is there any way to select only the rows marked with a (*) out of these > without doing a join? I.e. I wish to find the row with the highest > Date for each Key and use the Value from that. > > Regards, > > -- Raju > -- > Raj Mathur raju@kandalaya.org http://kandalaya.org/ > GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F > PsyTrance & Chill: http://schizoid.in/ || It is the mind that moves > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql >
Re: For each key, find row with highest value of other field
От:
"Fernando Hevia" <fhevia@ip-tel.com.ar>
Дата:
> Raj Mathur wrote: > > I have some data of the form: > > Key | Date | Value > A | 2008-05-01 | foo * > A | 2008-04-01 | bar > A | 2008-03-01 | foo * > B | 2008-03-04 | baz > B | 2008-02-04 | bar > C | 2008-06-03 | foo * > C | 2008-04-04 | baz > C | 2008-03-04 | bar > > Is there any way to select only the rows marked with a (*) > out of these without doing a join? I.e. I wish to find the > row with the highest Date for each Key and use the Value from that. > This should do it: Select value from table awhere date = (select max(b.date) from table b where b.key = a.key) q; Regards, Fernando.
Re: For each key, find row with highest value of other field
От:
Mark Roberts <mailing_lists@pandapocket.com>
Дата:
select distinct on (Key) Key, Date, Value from <