最近项目中要出一个按月、周、日统计的报表
某年按月分组:
Sql代码
SELECT A.D as label,NVL(B.NUM,0) AS value
FROM
(
SELECT ROWNUM AS D FROM SYS_UNUSE WHERE ROWNUM < 13
) A
LEFT JOIN
(
SELECT TO_CHAR(T.STARTTIME,'MM') AS D,COUNT(1) AS NUM FROM CALL_HIS T
WHERE T.STARTTIME>=:prStartDate AND T.STARTTIME<:prEndDate
GROUP BY TO_CHAR(T.STARTTIME,'MM')
) B ON A.D=B.D ORDER BY A.D
某月按日分组:
Sql代码
SELECT A.D as label,NVL(B.NUM,0) AS value
FROM
(
SELECT ROWNUM AS D FROM SYS_UNUSE WHERE ROWNUM <= TO_CHAR(LAST_DAY(:prDate),'DD')
) A
LEFT JOIN
(
SELECT TO_CHAR(T.STARTTIME,'MM') AS D,COUNT(1) AS NUM FROM CALL_HIS T
WHERE T.STARTTIME>=:prStartDate AND T.STARTTIME<:prEndDate
GROUP BY TO_CHAR(T.STARTTIME,'MM')
) B ON A.D=B.D ORDER BY A.D
按周统计:
Sql代码
SELECT A.D as label,NVL(B.NUM,0) AS value
FROM
(
SELECT TO_CHAR(:prDate+ROWNUM-1,'yyyy-MM-DD') as D FROM SYS_UNUSE WHERE ROWNUM <= 7
) A
LEFT JOIN
(
SELECT TO_CHAR(T.STARTTIME,'yyyy-MM-DD') AS D,COUNT(1) AS NUM FROM CALL_HIS T
WHERE T.STARTTIME>=:prStartDate AND T.STARTTIME<:prEndDate
GROUP BY TO_CHAR(T.STARTTIME,'yyyy-MM-DD')
) B ON A.D=B.D ORDER BY A.D
说明:SYS_UNUSE表是一个没用的表,跟业务没有任何关系,表里只有100条数据,我这里是足够用了。
关键词标签:oracle
相关阅读
热门文章 Oracle中使用alter table来增加,删除,修改列oracle中使用SQL语句修改字段类型-oracle修使用低权限Oracle数据库账户得到管理员权限Oracle对user的访问控制
人气排行 ORACLE SQL 判断字符串是否为数字的语句Oracle中使用alter table来增加,删除,修改列的语法ORACLE和SQL语法区别归纳(1)oracle grant 授权语句如何加速Oracle大批量数据处理Oracle删除表的几种方法ORACLE修改IP地址后如何能够使用Oracle 10g创建表空间和用户并指定权限
查看所有0条评论>>