oracle怎么统计人数,oracle 统计每月累积购买人数

oracle 可有什么方法 统计每月累积购买人数

比如说有个门店 2008年购买商品的人数

表:t_buy_log  字段 f_username 用户名称;购买时间f_buytime

1 如果是统计每月购买人数

select to_char(f_buytime,'yyymm'),count(distinct f_username)

from t_buy_log

group by to_char(f_buytime,'yyymm')

order by to_char(f_buytime,'yyymm') asc

结果:

1月 100人

2月 150人

3月 50人

2 如果统计每月累积购买人数 ?

1月 100人

2月 是1月和2月的购买人数 客户有重复 值在100-250之间

3月 是1-3月的购买人数

这个该怎么写呢?

用分析函数的SUM 好像不行

1-1

select to_char(f_buytime,'yyymm'),count(distinct f_username)

from t_buy_log

WHERE to_char(f_buytime,'yyymm')='200901'

1-2

select to_char(f_buytime,'yyymm'),count(distinct f_username)

from t_buy_log

WHERE to_char(f_buytime,'yyymm') between '200901'  and '200902'

1-3

select to_char(f_buytime,'yyymm'),count(distinct f_username)

from t_buy_log

WHERE to_char(f_buytime,'yyymm') between '200901'  and '200903'

Create Table t_tmp_test As

select oldtable.tm,

(

select/*+parallel(t,20)*/ count(distinct f_username)

from t_Base_Prouser_Suc t where to_char(f_Expectenddate, 'yyyyMM') <= oldtable.tm

And t.f_Source In ( Select f_buymodeid from T_base_Flat_Type Where f_department = 1)

) rs

from

(

select   to_char(add_months(to_date('2007-01-01','YYYY-MM-DD'),(Level-1)),'yyyymm') tm

from dual

connect by level < months_between(to_date('2009-12-01','YYYY-MM-DD'),to_date('2007-01-01','YYYY-MM-DD'))+1

) oldtable

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值