问题
id date value
1 08.03.2015 20:01:47 1383322
2 08.03.2015 20:14:01 1383382
3 08.03.2015 20:19:17 1383412
4 08.03.2015 20:22:45 1383441
5 08.03.2015 20:35:55 1383551
6 08.03.2015 20:42:43 1383604
7 08.03.2015 20:44:56 1383630
8 08.03.2015 21:08:17 1383880
9 08.03.2015 21:16:36 1383959
10 08.03.2015 22:37:48 1384613
11 08.03.2015 22:40:12 1384642
12 08.03.2015 22:42:25 1384667
13 08.03.2015 22:44:38 1384696
14 08.03.2015 22:46:51 1384721
15 08.03.2015 22:49:58 1384752
16 08.03.2015 22:52:17 1384775
17 08.03.2015 22:54:50 1384804
How can i get first value of each hours in oracle?
like that:
id date value
1 08.03.2015 20:01:47 1383322
8 08.03.2015 21:08:17 1383880
10 08.03.2015 22:37:48 1384613
回答1:
If you want the first value, then you can use row_number()
or keep
:
select t.*
from (select t.*,
row_number() over (partition by to_char(date, 'YYYY-MM-DD HH24'),
order by date) as seqnum
from table t
) t
where seqnum = 1;
回答2:
GROUp BY date in hours
SELECT date, MIN(value)
FROM table
GROUP BY TO_CHAR(date,'HH24');
Or using TRUNC
SELECT date, MIN(value)
FROM table
GROUP BY TRUNC(date, 'HH24');
来源:https://stackoverflow.com/questions/29230782/how-can-i-get-first-value-of-each-hours-oracle