zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    lua 根据路径获取文件名
    python中的re模块
    正则表达式中的开头和结尾
    正则表达式匹配多个字符
    正则表达式中匹配单个字符
    正则表达式的作用
    gevent实现协程
    greenlet实现协程
    生成器的使用注意
    生成器实现斐波那契数列
  • 原文地址:https://www.cnblogs.com/xinxin-ting/p/8024561.html
Copyright © 2011-2022 走看看