Oracle 分析函数 over

    最近在做一个OA系统的统计模块,里面有个功能需要统计出每天新增的用户和累计新增的用户, 只有一张 用户登录的表(用户登录时间,用户ID,等等),效果图:

 

分析:1,同一用户在一天之内可以登录多次,在这一天表中,会有多条这个用户的记录,但统计的时候,只能算一次

          2,肯定会用登录时间分组,用户ID去重,把数据统计出来

由于是以前的项目,种种限制吧,必须用一个sql写出来,查了好久,SQL如下:

<!-- 总用户-->
    <select id="datalistPage" resultType="UserTotleVo" parameterType="Page">
        select daytime,xinzeng,totle from (
        select daytime,xinzeng,sum(xinzeng) over(order by  daytime) as totle from (
        select daytime, count(distinct user_uuid) as xinzeng from(
        select  to_char(to_date(CREATE_TIME,'yyyy-MM-dd hh24:mi:ss'),'yyyy-MM-dd') as daytime , user_uuid
        from M_LOGGING_INFO ) WHERE 1=1
        <if test="pd.lastStart!=null and pd.lastStart!=''">
            and daytime  >= #{pd.lastStart}
        </if>
        <if test="pd.lastEnd!=null and pd.lastEnd!=''">
            and daytime  <= #{pd.lastEnd}
        </if>
        group by daytime order by daytime desc )) order by daytime desc

    </select>

两点:1,Oracle的分析函数 over

          2,时间格式的转换,加个去重,正好可以统计出每天的 用户量

 

此微博只为记录自己的成长经历,没有关于分析函数的简介。想学习可以去:https://www.cnblogs.com/wuyisky/archive/2010/02/24/oracle_over.html

 

posted @ 2017-12-11 18:51  Mr.Duanxj  阅读(264)  评论(0编辑  收藏  举报