how to get Max(value) with its corresponding datetime ... [message #596399] |
Sun, 22 September 2013 11:33 |
|
yasinirshad
Messages: 12 Registered: January 2013
|
Junior Member |
|
|
Hi,
This is my table
ID timestamp value
1 2013-09-09 01:09:00.000 1234
2 2013-09-09 02:00:00.000 123
1 2013-09-09 03:09:00.000 1233
2 2013-09-09 21:09:00.000 125
I need to find max(value) with its corresponding time stamp .. this table has approximately 500000 records with 180 distinct IDs. Need to find max(value) group by IDs. Please let me know the Query ...
Expected result:
ID timestamp value
1 2013-09-09 01:09:00.000 1234
2 2013-09-09 21:09:00.000 125
We have a query but its returns 00 in hh:mm:ss instead of exact timestamp.
Thanks.
|
|
|
|
|
|
|
|
Re: how to get Max(value) with its corresponding datetime ... [message #596407 is a reply to message #596406] |
Sun, 22 September 2013 14:31 |
|
yasinirshad
Messages: 12 Registered: January 2013
|
Junior Member |
|
|
ok here is the table
CREATE TABLE Frequency (
table_index number,
timestamp datetime,
value decimal
)
This is my Sample data in table:
table_index timestamp value
1 2013-09-09 01:09:00.000 1234
2 2013-09-09 02:00:00.000 123
1 2013-09-09 03:09:00.000 1233
2 2013-09-09 21:09:00.000 125
I need to find max(value) with its corresponding time stamp .. this table has approximately 500000 records with 180 distinct table_index. Need to find max(value) group by table_index. Please let me know the Query ...
Expected result:
table_index timestamp value
1 2013-09-09 01:09:00.000 1234
2 2013-09-09 21:09:00.000 125
Thanks.
[Updated on: Sun, 22 September 2013 14:35] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: how to get Max(value) with its corresponding datetime ... [message #596498 is a reply to message #596414] |
Tue, 24 September 2013 00:33 |
|
yasinirshad
Messages: 12 Registered: January 2013
|
Junior Member |
|
|
I tried below queries but get error:
select * from (Select table_index,hist_timestamp, max(value) Value,row_number() over(partition by table_index order by Value desc)rn from freq where
hist_timestamp >= to_date('09/20/2013 19:00:00', 'mm/dd/yyyy hh24:mi:ss') AND
hist_timestamp < to_date('09/20/2013 20:00:00', 'mm/dd/yyyy hh24:mi:ss') order by table_index) where rn=1;
ORA-00937: not a single-group group function
======================================================================
select * from (Select table_index,hist_timestamp, max(value) Value,row_number() over(partition by table_index order by Value desc)rn from freq where
hist_timestamp >= to_date('09/20/2013 19:00:00', 'mm/dd/yyyy hh24:mi:ss') AND
hist_timestamp < to_date('09/20/2013 20:00:00', 'mm/dd/yyyy hh24:mi:ss') group by table_index,hist_timestamp) where rn=1;
ORA-00979: not a GROUP BY expression
========================================================================
With e As (Select *,row_number() over (partition by table_index order by Value desc) as Recency from freq where
hist_timestamp >= to_date('09/20/2013 19:00:00', 'mm/dd/yyyy hh24:mi:ss') AND
hist_timestamp < to_date('09/20/2013 20:00:00', 'mm/dd/yyyy hh24:mi:ss'))
select * from e where Recency = 1;
ORA-00923: FROM keyword not found where expected
|
|
|
|
|