用於日誌統計,要求在指定的時間範圍內每天都要統計
要求 日期,5<=T<10,10<=T<20,20<=T<30,30<=T<40,T>=40,異常總數
with a as(
select to_date('2016-11-1','yyyy-mm-dd hh24:mi:ss') startdate,to_date('2017-01-22','yyyy-mm-dd hh24:mi:ss') enddate from dual)select t.v,nvl(t1.cou,0),nvl(t2.cou,0),nvl(t3.cou,0),nvl(t4.cou,0),nvl(t5.cou,0),nvl(t6.cou,0) from (
select to_char(t,'yyyy-mm-dd') v
from (select distinct startdate + level - 1 t
from a
connect by level <= enddate - startdate + 1) order by t ) t ,
(select count(log.timespan) cou,to_char(log.logdatetime,'yyyy-mm-dd') su from sys_runlog log where log.logtype log.timespan >= 0 and log.timespan < 10 group by to_char(log.logdatetime,'yyyy-mm-dd')) t1 ,
(select count(log.timespan) cou,to_char(log.logdatetime,'yyyy-mm-dd') su from sys_runlog log where log.timespan >= 10 and log.timespan < 20 group by to_char(log.logdatetime,'yyyy-mm-dd')) t2,
(select count(log.timespan) cou,to_char(log.logdatetime,'yyyy-mm-dd') su from sys_runlog log where log.timespan >= 20 and log.timespan < 30 group by to_char(log.logdatetime,'yyyy-mm-dd')) t3,
(select count(log.timespan) cou,to_char(log.logdatetime,'yyyy-mm-dd') su from sys_runlog log where log.timespan >= 30 and log.timespan < 40 group by to_char(log.logdatetime,'yyyy-mm-dd')) t4,
(select count(log.timespan) cou,to_char(log.logdatetime,'yyyy-mm-dd') su from sys_runlog log where log.timespan >= 40 group by to_char(log.logdatetime,'yyyy-mm-dd')) t5,
(select count(log.timespan) cou,to_char(log.logdatetime,'yyyy-mm-dd') su from sys_runlog log where log.logtype=? group by to_char(log.logdatetime,'yyyy-mm-dd')) t6
where t.v = t1.su(+) and t.v = t2.su(+) and t.v = t3.su(+) and t.v = t4.su(+) and t.v = t5.su(+) and t.v = t6.su(+)
order by t.v
統計登錄日誌 要求統計每天登錄的總人數 一個人登錄一次或多次也只能算是一人
(select count(distinct t.user_account) cou,to_char(t.time,'yyyy-mm-dd') su from ops_log_login t group by to_char(t.time,'yyyy-mm-dd')) t1,
用oracle創建一個虛擬表 內容爲指定的時間範圍
with a as(
select to_date('2016-11-1','yyyy-mm-dd hh24:mi:ss') startdate,to_date('2017-01-22','yyyy-mm-dd hh24:mi:ss') enddate from dual)select t.v from (
select to_char(t,'yyyy-mm-dd') v
from (select distinct startdate + level - 1 t
from a
connect by level <= enddate - startdate + 1) order by t ) t