select count(*) as succ from sp_sms_finreq where smtype in (select distinct a.smstype from ib_ru_smsrule a, ib_ru_credstatechg b where a.ruleid = b.smsruleid and b.ruletype in ('0','3','4','5','6','7','9','10','11'))怎么给改造成没有子查询,也就是如传说的分解掉?也就是说去掉select distinct a.smstype from ib_ru_smsrule a, ib_ru_credstatechg b where a.ruleid = b.smsruleid and b.ruletype in ('0','3','4','5','6','7','9','10','11')之外的括号,help!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    这个没法去掉的,唯一可以改的就是用exists替代 IN
      

  2.   

    这一串数据in ('0','3','4','5','6','7','9','10','11')) 是从哪里来的?
    如果是从另外一个表出来,那么只能用exists来代替
      

  3.   

    --1993年本人也在深圳做过SMT主管,哈哈。
    --试一下:select a.count(*) succ 
           from  sp_sms_finreq a,ib_ru_smsrule b, ib_ru_credstatechg c 
           where a.smtype=b.smstype and 
                 b.ruleid = c.smsruleid and 
                 c.ruletype in ('0','3','4','5','6','7','9','10','11');
      

  4.   

    这怎么去分解啊,要么用exists代替in,可能会快点,或者就用3楼的方法.
    下面是用exists代替inselect count(*) as succ from sp_sms_finreq c where exists(select 1 from ib_ru_smsrule a, ib_ru_credstatechg b where
    a.smtype=c.smtype and a.ruleid = b.smsruleid and b.ruletype in ('0','3','4','5','6','7','9','10','11'))
      

  5.   


    暂时没有办法  我也是笨方法select count(*)
    from   sp_sms_finreq e,
           (select distinct a.smstype stype 
            from ib_ru_smsrule a, ib_ru_credstatechg b 
            where a.ruleid = b.smsruleid 
            and b.ruletype in ('0','3','4','5','6','7','9','10','11')
           )f
    where  e.smtype=f.stype
      

  6.   

    分解倒是可以分解,问题是分解的目的是为了优化吗?如果是为了优化,去掉子查询不见得是最好的办法
    具体问题要具体分析
    下面是分解后的SQL:
    SELECT COUNT(DISTINCT a.rowid) AS SUCC
      FROM SP_SMS_FINREQ A 
      JOIN IB_RU_SMSRULE B ON A.SMTYPE=B.SMSTYPE
      JOIN IB_RU_CREDSTATECHG C B.RULEID = C.SMSRULEID
     WHERE C.RULETYPE IN ('0', '3', '4', '5', '6', '7', '9', '10', '11'))
      

  7.   

    不知道ib_ru_smsrule a, ib_ru_credstatechg b数据量的大小
    select count(s.*) as succ
      from sp_sms_finreq s, ib_ru_smsrule a
     where s.smtype = a.smstype
       and exists
     (select 1
              from ib_ru_credstatechg b
             where b.smsruleid=a.ruleid
               and b.ruletype in ('0', '3', '4', '5', '6', '7', '9', '10', '11')))
      

  8.   

    select count(*) as succ 
     from sp_sms_finreq  As A, ( select distinct a.smstype 
                 from ib_ru_smsrule a, 
                 ib_ru_credstatechg    b
      where a.ruleid = b.smsruleid
            and b.ruletype in ('0','3','4','5','6','7','9','10','11')) 
    ) As B
    where A.smstype=B.smstype
      

  9.   

    SELECT COUNT(DISTINCT A.SMTYPE)  
    FROM ZYF_TAB1 A 
    JOIN ZYF_TAB2 B ON A.SMTYPE=B.RULEID 
    JOIN ZYF_TAB3 C ON B.RULEID=C.SMSRULEID
    WHERE C.RULETYPE IN ('0', '3', '4', '5', '6', '7', '9', '10', '11')
    是不是这样,运行统计是正确的,已经测试了
      

  10.   

    如果a.smtype是primary key,那么楼上的就是正确的.可看起来并不是这样