如何統計 一天24小時 每個小時的資料總數啊 sql怎么寫 求指點 謝謝
時間 條數?
1 33
2 2
3 98
............
24 11
uj5u.com熱心網友回復:
表 a 里面有個時間欄位 ORDERTIMEuj5u.com熱心網友回復:
把表結構和樣例資料貼出來吧uj5u.com熱心網友回復:
表名
orderList
欄位
createTime name .......
2014-02-14 12:11:22 test
uj5u.com熱心網友回復:
select trunc(createTime),to_char(createTime,'hh24'),count(*) from orderList group by trunc(createTime),to_char(createTime,'hh24');uj5u.com熱心網友回復:
不好意思可能是我沒說清楚,你這樣是查詢所有的資料 我只要查一天之類的資料, 并且把為空的 也查詢出來 比如2點 0 3點0.你這樣查詢 資料為空的 查詢不出來 謝謝
uj5u.com熱心網友回復:
要查一天的就加上where條件,至于資料為空的也要查出來的話可以考慮建一個表,存00~23這些值,左連接一下
uj5u.com熱心網友回復:
create table orderList(新年,我的寫法。
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;
uj5u.com熱心網友回復:
樓主 能否把你這個問題給我解答一下 小弟碰到幾天了 沒點頭緒 能否加我QQ 1628288336uj5u.com熱心網友回復:
--創建測驗表
--回圈插入測驗資料
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');
uj5u.com熱心網友回復:
http://blog.csdn.net/qq_28766327/article/details/77864672我的解決辦法
uj5u.com熱心網友回復:
為什么不匯出到excel表 一個sum陳述句就解決了?uj5u.com熱心網友回復:
不好意思,我理解錯了!uj5u.com熱心網友回復:
為什么不匯出到excel表 一個sum陳述句就解決了?
uj5u.com熱心網友回復:
為什么不匯出到excel表 一個sum陳述句就解決了?
和你的意思一樣需要在excel表中體現,要用sum算總和,具體的圖在上面,能寫下sql嗎?在線等,謝謝
uj5u.com熱心網友回復:
--創建測驗表
--回圈插入測驗資料
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');
這個寫法可以
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/82492.html
標籤:開發
上一篇:【pl/sql】一次查詢多內網資料庫 【請高手指教】
下一篇:oracle ocp
