tags:

views:

30

answers:

2
create table v (mydate,value)
as
select to_date('20/03/2010 00','dd/mm/yyyy HH24'),98 from dual union all
select to_date('20/03/2010 01','dd/mm/yyyy HH24'),124 from dual union all
select to_date('20/03/2010 02','dd/mm/yyyy HH24'),140 from dual union all
select to_date('20/03/2010 03','dd/mm/yyyy HH24'),138 from dual union all
select to_date('20/03/2010 04','dd/mm/yyyy HH24'),416 from dual union all
select to_date('20/03/2010 05','dd/mm/yyyy HH24'),196 from dual union all
select to_date('20/03/2010 06','dd/mm/yyyy HH24'),246 from dual union all
select to_date('20/03/2010 07','dd/mm/yyyy HH24'),176 from dual union all
select to_date('20/03/2010 08','dd/mm/yyyy HH24'),124 from dual union all
select to_date('20/03/2010 09','dd/mm/yyyy HH24'),128 from dual union all
select to_date('20/03/2010 10','dd/mm/yyyy HH24'),32010 from dual union all
select to_date('20/03/2010 11','dd/mm/yyyy HH24'),384 from dual union all
select to_date('20/03/2010 12','dd/mm/yyyy HH24'),368 from dual union all
select to_date('20/03/2010 13','dd/mm/yyyy HH24'),392 from dual union all
select to_date('20/03/2010 14','dd/mm/yyyy HH24'),374 from dual union all
select to_date('20/03/2010 15','dd/mm/yyyy HH24'),350 from dual union all
select to_date('20/03/2010 16','dd/mm/yyyy HH24'),248 from dual union all
select to_date('20/03/2010 17','dd/mm/yyyy HH24'),396 from dual union all
select to_date('20/03/2010 18','dd/mm/yyyy HH24'),388 from dual union all
select to_date('20/03/2010 19','dd/mm/yyyy HH24'),360 from dual union all
select to_date('20/03/2010 20','dd/mm/yyyy HH24'),194 from dual union all
select to_date('20/03/2010 21','dd/mm/yyyy HH24'),234 from dual union all
select to_date('20/03/2010 22','dd/mm/yyyy HH24'),328 from dual union all
select to_date('20/03/2010 23','dd/mm/yyyy HH24'),216 from dual

From this table, how to rank() over 'value', partitioning by each hour of the day? and select only the 1st ranked result?

A: 
select mydate,value from
(
select *,rank() over (partition by dateadd(hour,datediff(hour,0,mydate),0) as sno from v
) t
where sno=1
Madhivanan
A: 
SELECT * FROM 
(
 select value,MYDATE, 
 rank() over (partition by EXTRACT(HOUR FROM DATE MYDATE) ORDER BY value) RK 
 FROM V
) 
WHERE RK = 1;
Bharat