Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: how to write this sql query
Guang,
Add MAX(score) over() to your query and that should do it, so:
select DISTINCT QUERYID,
FIRST_VALUE(SUBJID) OVER (PARTITION BY QUERYID ORDER BY score DESC),
MAX(score) OVER()
from blastresults where QUERYID=62;
-----Original Message-----
From: Guang Mei [mailto:gmei_at_incyte.com]
Sent: Thursday, June 17, 2004 1:20 PM
To: Oracle-L-freelists
Subject: how to write this sql query
Running oracle 8173 on Sun
MT_at_rex-SQL> select QUERYID,SUBJID,score from blastresults where
QUERYID=62;
QUERYID SUBJID SCORE
---------- ---------- ----------
62 646558 411 62 55957 406 62 463496 290 62 11382 2167 62 6279 1864 62 7203 1784 62 9663 1754 MT_at_rex-SQL> select DISTINCT QUERYID, FIRST_VALUE(SUBJID) OVER (PARTITION BY QUERYID ORDER BYscore DESC)
QUERYID FIRST_VALUE(SUBJID)OVER(PARTITIONBYQUERYIDORDERBYSCOREDESC)
---------- -----------------------------------------------------------
62 11382
What I want from the above 7 rows is
62 --- queryid (I already have , this is not a problem). 2167 --- max(score) 11382 --- subjid that corresposnding to max(score)
The second query does give me the subjid that corresponds to max(score),
but
I cann't seem to be able to get the score value at the same time.
And I don't want to query the table twice. Any ideas?
TIA. Guang
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.htmlput 'unsubscribe' in the subject line.
-----------------------------------------------------------------
----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to: oracle-l-request_at_freelists.org