group by - oracle query to get max hour every day, and corresponding row values -
i'm having hard time creating query following:
i have table, called log:
id | insert_time | log_value ---------------------------------------- 1 | 2013-04-29 18:00:00.000 | 160473 2 | 2013-04-29 21:00:00.000 | 154281 3 | 2013-04-30 09:00:00.000 | 186552 4 | 2013-04-30 14:00:00.000 | 173145 5 | 2013-04-30 14:30:00.000 | 102235 6 | 2013-05-01 11:00:00.000 | 201541 7 | 2013-05-01 23:00:00.000 | 195234
what want build query returns, each day, last values inserted (using max value of insert_time). i'm interested in date part of column, , in column log_value. so, resultset after running query:
2013-04-29 154281 2013-04-30 102235 2013-05-01 195234
i guess need use group on insert_time column, along max() function, doing that, can't seem log_value. can me on this, please?
(i'm on oracle 10g)
select trunc(insert_time), log_value ( select insert_time, log_value, rank() on (partition trunc(insert_time) order insert_time desc) rnk log) rnk = 1
is 1 option. uses analytic function rank
identify row latest insert_time
on each day.
Comments
Post a Comment