Oracle 分析函數 over

來源:互聯網
上載者:User

標籤:.com   時間   param   rto   學習   功能   有關   com   distinct   

    最近在做一個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

 

Oracle 分析函數 over

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.