Oracle 分析函數 over
阿新 • • 發佈:2017-12-11
格式 clas 限制 .com 自己 tin day 用戶 creat
最近在做一個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