2

我有一个简单的查询,每天都会吐出 new_users ......

Select trunc(create_dtime),Count(Player_Id) as New_Users
  From Player
 Where Trunc(Create_Dtime) >= To_Date('2011-APR-22','yyyy-mon-dd')
 Group By Trunc(Create_Dtime)
 Order by trunc(Create_Dtime)

随着每一天的继续,我希望这个总数 new_users ......所以例如,如果当前查询吐出一个结果:

Apr 22
Apr 23
Apr 24 of 1000 new users each day...

我希望这个新查询说:

Apr 22 = 1000 New users
Apr 23 = 2000
Apr 24 = 3000

...依此类推,直到最后一个日期(今天)在一行中显示新用户总数。

让我知道这是否足够清楚。

4

1 回答 1

1

我会使用累积和来做到这一点,Oracle 很乐意通过分析函数支持它:

select thedate, New_Users,
       sum(New_Users) over (order by thedate) as Cumulative_New_Users
from (Select trunc(create_dtime) as thedate, Count(Player_Id) as New_Users
      From Player
      Where Trunc(Create_Dtime) >= To_Date('2011-APR-22','yyyy-mon-dd')
      Group By Trunc(Create_Dtime)
     ) t
Order by 1
于 2012-09-13T20:22:48.173 回答