如何统计 一天24小时 每个小时的数据总数啊 sql怎么写 求指点 谢谢
时间 条数
1 33
2 2
3 98
............
24 11
时间 条数
1 33
2 2
3 98
............
24 11
解决方案 »
- RMAN-06023: no backup or copy of datafile 6 found to restore
- 求这条sql该怎么写。
- 请教!多用户通过DBLINK访问远程数据库产生多SESSION的问题
- 各位大侠请帮忙~急!!!关于日期输出显示的问题
- 问个日期转换的问题:我a表rq字段内容(DATE型)格式为:29-1月 -05,b表rq字段内容(DATE型)格式为:01/23/2005 00:00:00
- oracle 8i中的空操作语句怎么写
- 如何在PL-sql里面实现全外联?
- 十万火急,在线给分
- 触发器表在哪。
- 下面情况的sql语句怎么写?急,在线给分!!
- 如何获取一个sql语句中各个字段的类型信息?
- sql 语句问题请高人指点
表名
orderList 字段
createTime name .......
2014-02-14 12:11:22 test
不好意思可能是我没说清楚,你这样是查询所有的数据 我只要查一天之类的数据, 并且把为空的 也查询出来 比如2点 0 3点0.你这样查询 数据为空的 查询不出来 谢谢
要查一天的就加上where条件,至于数据为空的也要查出来的话可以考虑建一个表,存00~23这些值,左连接一下
createTime date default(sysdate),
name varchar2(20)
)
----------------------------------------
insert into orderList (name) values ('aa');
insert into orderList (name) values ('bb');
insert into orderList (name) values ('cc');
insert into orderList (name) values ('dd');
insert into orderList (name) values ('ee');
insert into orderList (name) values ('ff');
----------------------------------------
with C_tab as(
select to_char(sysdate,'yyyy-mm-dd')||' '||lpad(level,2,'0') atime from dual connect by level <=24)
select b.atime,count(nvl(a.createtime,null)) from orderList a right join C_tab b on to_char(a.createtime,'yyyy-mm-dd hh24') = b.atime
group by b.atime
----------------------------------------
drop table orderList;新年,我的写法。
--循环插入测试数据
declare n number;
begin
n:=0;
while n<50000 loop
n :=n+1;
insert into hour_test
select * from (
select rownum rn,to_date('2017-01-01', 'yyyy-mm-dd hh:mi:ss')+ rownum/24 add_hour from dual
connect by rownum<25) a
where a.rn =(select round(dbms_random.value(1,24)) from dual);
end loop;
commit;
end ;
--查询结果
select to_char(add_hour,'hh24') hour ,count(*) n from hour_test
group by to_char(add_hour,'hh24')
order by to_char(add_hour,'hh24');
我的解决办法