Statistics in the t_tjsj table according to cjsj (date type) every 5 minutes to count the number in the one-hour time period from 0:00 to 1:00:
select lpad(floor(to_char(cjsj,'mi')/5)*5,2,0) cjsj, count(bh) num
from t_tjsj where cjsj>to_date('2018-04-15 00:00:00','yyyy-MM-dd hh24:mi:ss')
and cjsj<=to_date('2018-04-15 01:00:00','yyyy-MM-dd hh24:mi:ss')
group by lpad(floor(to_char(cjsj,'mi')/5)*5,2,0)
order by lpad(floor(to_char(cjsj,'mi')/5)*5,2,0) ;
Statistical expected results:
cjsj | on one |
05 | 111 |
10 | 232 |
15 | 211 |
20 | 12 |
25 | 3214 |
30 | 34 |
35 | 234 |
40 | 454 |
45 | 674 |
50 | 86 |
55 | 35 |
Statistics in the t_tjsj table according to cjsj (date type) count the number of every 5 minutes in a day from 0:00 to 24:00:
select to_char(cjsj,'hh24')||':'||lpad(floor(to_char(cjsj,'mi')/5)*5,2,0) cjsj, count(bh) num
from t_tjsj where cjsj>to_date('2018-04-15 00:00:00','yyyy-MM-dd hh24:mi:ss')
and cjsj<=to_date('2018-04-15 01:00:00','yyyy-MM-dd hh24:mi:ss')
group by to_char(cjsj,'hh24')||':'||lpad(floor(to_char(cjsj,'mi')/5)*5,2,0)
order by to_char(cjsj,'hh24')||':'||lpad(floor(to_char(cjsj,'mi')/5)*5,2,0) ;
Key functions:
to_char(cjsj,'hh24') ---- time to take hours
lpad(floor(to_char(cjsj,'mi')/5)*5,2,0) -- the time takes the corresponding five-minute segment