表1、
Id name time
13 h    2009-09-30
14 i    2009-09-30
15 j    2009-09-30
16 k    2009-09-30
1  a    2009-10-01
2  b   2009-10-01
3  c   2009-10-02
4  d   2009-10-03
5  e   2009-10-03
6  f   2009-10-03
7  g   2009-10-04
 结果
 
time       daycounts       counts
2009-09-30  4(新增)      (包括这个日期之前的所有人数)   
2009-10-01  2               6
2009-10-02  1               7
2009-10-03  3               10
2009-10-04  1               11

解决方案 »

  1.   

    一个sql估计写不出来,建议你用存储过程,建个临时表保存
      

  2.   

    不好意思刚掉线了
    试试这个
    select t.time,count, sum(count) over( order by time)
      from (select time,count(*) count from test  group by time) t
      

  3.   

    select time,count(1)daycounts,sum(count(1))over(order by time) counts
    from table1
    group by time
      

  4.   

    厉害
    我还在那捣鼓了10几分钟没捣鼓出来
    帮你试了一下
    SQL> select * from t1;        ID NAME       TIME
    ---------- ---------- ----------
             1 a          2009-09-30
             2 b          2009-09-30
             3 c          2009-09-29
             4 d          2009-09-28SQL> select time,count(1)daycounts,sum(count(1))over(order by time) counts
      2  from t1
      3  group by time;TIME        DAYCOUNTS     COUNTS
    ---------- ---------- ----------
    2009-09-28          1          1
    2009-09-29          1          2
    2009-09-30          2          4SQL>
      

  5.   

    如果在结果上加个周累计,月累计的话
    结果如下
    time      daycounts      counts 
    2009-09-30  4(新增)      (包括这个日期之前的所有人数)  
    2009-10-01  2              6 
    2009-10-02  1              7 
    2009-10-03  3              10 
    2009-10-04  1              11
    周累计       11             11
    ····      ····           ····
    ····      ····           ····
    ····      ····           ····
    月累计      ····           ····
      

  6.   

    select time,count(1)daycounts,sum(count(1))over(order by time) counts 
    from table1 
    group by rollup(to_char(time,'mm'))
      

  7.   

    时间字段是varchar型的还是date型
      

  8.   

    不好意思,刚才比较忙,
    varchar型
      

  9.   

    周统计月统计的部分可以union all到原语句的后面