Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Writing a query - 10g

$
0
0
Hi

I have an table containing hourly values and I want to write a query to extract a couple of columns based on the maximum value of one of the extracted columns. The query I wrote is:

Code:

SELECT * FROM                                               
(SELECT DATETIME,NODE,COL1 AA, ((COL2+COL3)/COL1) BB
FROM                                                     
TABLE
WHERE DATETIME BETWEEN TRUNC(SYSDATE)-3 and TRUNC(SYSDATE)-2-1/86400 AND NODE='ABC')
WHERE COL1 in                     
(SELECT MAX(COL1)
FROM
(SELECT DATETIME, COL1
FROM TABLE
WHERE DATETIME BETWEEN TRUNC(SYSDATE)-3 and TRUNC(SYSDATE)-2-1/86400 AND NODE='ABC'))

The above gives one row in the form:

Code:

DATETIME NODE AA BB
This query doesn't look very efficient to me. Moreover, I can only run the query for one day.

Is there a way I can get the above-mentioned for more than 1 day? I need to query/compute values based on the maximum value of COL1 out of 24 hourly values for each day.

Regards
Shajju

Viewing all articles
Browse latest Browse all 13329

Trending Articles