执行这样一个语句,查询数据约10000条,从1200万条数据中,十分钟了还没结果,请教高手给出意见,看看能怎么改。
select count(*) num_1,
decode(sign(substr(f.PURCHASE_TIME,1,4) - '2005'),0,'2005',1,substr(f.PURCHASE_TIME,1,4),'-1','2005') sub_1,
t.CUSTOMER_TYPE
from FOUNDER_STAT.TBL_PRODUCT f,FOUNDER_STAT.TBL_CUSTOMER t
where f.customer_no = t.customer_no
and t.customer_status = '1'
and f.purchase_time >= '20090101'
and f.purchase_time <= '20090202'
group by decode(sign(substr(f.PURCHASE_TIME,1,4) - '2005'),0,'2005',1,substr(f.PURCHASE_TIME,1,4),'-1','2005'), t.CUSTOMER_TYPE

解决方案 »

  1.   

    1200万数据有没有用分区表了?我看你的查询条件,看上去好象没有结果的吧?
    条件:
    and f.purchase_time >= '20090101'
    and f.purchase_time <= '20090202'
    然后:
    sign(substr(f.PURCHASE_TIME,1,4) - '2005')的结果为0,1,-1
    ???
      

  2.   


    select count(主键) num_1,
    decode(sign(substr(f.PURCHASE_TIME,1,4) - '2005'),1,substr(f.PURCHASE_TIME,1,4),'2005') sub_1,t.CUSTOMER_TYPE
    from FOUNDER_STAT.TBL_PRODUCT f,FOUNDER_STAT.TBL_CUSTOMER t
    where f.customer_no = t.customer_no
    and t.customer_status = '1'
    and f.purchase_time >= '20090101'
    and f.purchase_time <= '20090202'
    group by decode(sign(substr(f.PURCHASE_TIME,1,4) - '2005'),1,substr(f.PURCHASE_TIME,1,4),'2005'),
    t.CUSTOMER_TYPE
    customer_status 上建立索引。
    还不行,就贴执行计划
      

  3.   

    我的目的是这样的表
       05及以前 06 07 08 09
    个人 1       2  3 5 5
    单位 3       4  5 5 5
    我觉得应该不算太复杂吧?为啥PL执行半天也执行不完?跟死机了一样。
    另外,customer_status不能索引。
    我是做报表用的,不是只要结果,所以也不能用JOB。各位还有啥好主意没?
    1楼的怀疑没问题,库里存的就是20080808这样的格式。
      

  4.   

    不好意思,是我迷糊了,我要查年
    应该是这样,
    and f.purchase_time >= '20090101' 
    and f.purchase_time <= '20090202' 
      

  5.   

    做报表为什么就不能建立索引了呢?1200w的数据量,还不能用索引。没办法调优的。
    而其从你的需求来看,你写的这个SQL貌似达成不了你的目标。
      

  6.   

    1,把=条件号码去掉,试试看呢:select count(*) num_1,
    decode(sign(substr(f.PURCHASE_TIME,1,4) - '2005'),0,'2005',1,substr(f.PURCHASE_TIME,1,4),'-1','2005') sub_1,
    t.CUSTOMER_TYPE
    from FOUNDER_STAT.TBL_PRODUCT f,FOUNDER_STAT.TBL_CUSTOMER t
    where f.customer_no = t.customer_no
    and t.customer_status = '1'
    and f.purchase_time > '20081231' //换成
    and f.purchase_time < '20090203'
    group by decode(sign(substr(f.PURCHASE_TIME,1,4) - '2005'),0,'2005',1,substr(f.PURCHASE_TIME,1,4),'-1','2005'), t.CUSTOMER_TYPE
      

  7.   

    靠,沾错了
    and f.purchase_time >= '2008' 
    and f.purchase_time <= '2009' 
      

  8.   

    你f.PURCHASE_TIME这个字段是什么格式的?
    日期能直接这么用吗?
    左边的是字符川‘2008’,你不做任何处理这么样能比较吗?
      

  9.   

    谢谢各位
    表结构是这样的,
    表tbl_customer
    customer_no,customer_status,customer_type
    a1234    1   个人用户
    a1224    0   企业用户
    表tbl_product  每条记录对应一条产品
    customer,purchase_time,product_no
    a1234    2006-06-04    ****8
    a1224    2008-08-08    ****9
    目的是查出
               2005及以前 2006
    单位用户    购买数量   购买数量
    个人用户    购买数量   购买数量刚才按6楼的办法查了一下,还是没结果。
    and f.purchase_time >= '2008'  应该是  substr(f.PURCHASE_TIME,1,4)  >='2008'
      

  10.   

    你的f.PURCHASE_TIME字段是VARCHAR2的吧?不是DATE
      

  11.   

    ....是VARCHAR2的,我就是按字符截出来的,
    业务上就是两个维度分组
    按 customer_type分类,按purchase_time分类
    中间是记录数量。
    不知道我说明白了没有