Erp100论坛's Archiver

xiangzhao 发表于 2008-7-12 15:06

统计这么慢,有什么办法

统计关联三张表,三张表数据都在百万。。。统计需要230多秒,正常吗

xiangzhao 发表于 2008-7-12 15:06

select count(distinct decode(to_char(a1.reg_time,'yyyymm'),'200709',a1.user_id,NULL)),
    count(distinct decode(to_char(a1.reg_time,'yyyy'),'2007',a1.user_id,NULL)),
     count(distinct decode(a2.status,'01',a1.user_id,NULL))
    from a1,b1,a3
    where
    a1.user_id=b1.user_id
    and     
    a1.user_id=a3.user_id
    and b1.year_month<='200709'
    and  (a1.pay_account_type is null
    or a1.pay_account_type!='IN00')

a1,a2是两个用户表,因为要使用每个表里的特殊字段,所以必须关联
b1是消费记录表

上面统计三个值,本月新增加用户中消费用户,本年新增加用户中的消费用户,期末有效用户数

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2007 Comsenz Inc.