標籤:.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