各位好,我想实现如下语句的功能,但报ora-22818错误。请问我该如何写呢?谢谢!
SELECT count(distinct LCPOL.CONTNO),
       LCPOL.RISKCODE,
       LCPOL.MANAGECOM,
       LCPOL.AGENTGROUP,
       LCPOL.SALECHNL,
       LCPOL.PAYENDYEAR,
       LCPOL.PAYINTV,
       LCPOL.YEARS,
       ljagetendorse.getmoney,
       LCPOL.AMNT,
       TO_CHAR(lpedorapp.confdate, 'YYYY-MM-DD'),
       LCCONT.SELLTYPE,
       --LJTEMPFEECLASS.PAYMODE,
       (select paymode from LJTEMPFEECLASS where ljtempfeeclass.otherno=lcpol.prtno and rownum=1) paymode,
       floor(months_between(lcpol.paytodate,lcpol.cvalidate)/12) polyear,
       nvl(lcpol.payendyearflag,'0'),
       nvl(lcpol.conttype,0)
  FROM lcpol,lccont,ljagetendorse,lpedoritem,lpedorapp
 WHERE lcpol.contno=lccont.contno
        and ljagetendorse.polno=lcpol.polno
and lpedoritem.edorno = LJAGetEndorse.Endorsementno 
and lpedorapp.EdorAcceptNo=lpedoritem.EdorAcceptNo
and lpedoritem.contno = lccont.contno
and LJAGetEndorse.Feeoperationtype in ('IC','IO','NI','PT','WA','XS','ZT','01','02')
and lccont.conttype='2'
and lpedorapp.confdate is not null
and lccont.signdate is not null
group by        LCPOL.RISKCODE,
       LCPOL.MANAGECOM,
       LCPOL.AGENTGROUP,
       LCPOL.SALECHNL,
       LCPOL.PAYENDYEAR,
       LCPOL.PAYINTV,
       LCPOL.YEARS,
       ljagetendorse.getmoney,
       LCPOL.AMNT,
       TO_CHAR(lpedorapp.confdate, 'YYYY-MM-DD'),
       LCCONT.SELLTYPE,
       --LJTEMPFEECLASS.PAYMODE,
       (select paymode from LJTEMPFEECLASS where ljtempfeeclass.otherno=lcpol.prtno and rownum=1),
       floor(months_between(lcpol.paytodate,lcpol.cvalidate)/12),
       nvl(lcpol.payendyearflag,'0'),
       nvl(lcpol.conttype,0)

解决方案 »

  1.   

    不好意思,sql有点长,其实问题就是内查询不能group by,可以简单一些,如下:
    SELECT count(distinct LCPOL.CONTNO), 
          (select paymode from LJTEMPFEECLASS where ljtempfeeclass.otherno=lcpol.prtno and rownum=1) paymode, 
          nvl(lcpol.conttype,0) 
      FROM lcpol,lccont,ljagetendorse,lpedoritem,lpedorapp 
    WHERE lcpol.contno=lccont.contno 
            and ljagetendorse.polno=lcpol.polno 
    and lpedoritem.edorno = LJAGetEndorse.Endorsementno 
    and lpedorapp.EdorAcceptNo=lpedoritem.EdorAcceptNo 
    and lpedoritem.contno = lccont.contno 
    group by  (select paymode from LJTEMPFEECLASS where ljtempfeeclass.otherno=lcpol.prtno and rownum=1), 
         nvl(lcpol.conttype,0)
      

  2.   

    ORA-22818 subquery expressions not allowed hereCause: An attempt was made to use a subquery expression where these are not supported.Action: Rewrite the statement without the subquery expression.
      

  3.   

    改成如下:
    SELECT B, C, COUNT(DISTINCT A)
      FROM (SELECT LCPOL.CONTNO A,
                   (SELECT PAYMODE
                      FROM LJTEMPFEECLASS
                     WHERE LJTEMPFEECLASS.OTHERNO = LCPOL.PRTNO
                       AND ROWNUM = 1) B,
                   NVL(LCPOL.CONTTYPE, 0) C
              FROM LCPOL, LCCONT, LJAGETENDORSE, LPEDORITEM, LPEDORAPP
             WHERE LCPOL.CONTNO = LCCONT.CONTNO
               AND LJAGETENDORSE.POLNO = LCPOL.POLNO
               AND LPEDORITEM.EDORNO = LJAGETENDORSE.ENDORSEMENTNO
               AND LPEDORAPP.EDORACCEPTNO = LPEDORITEM.EDORACCEPTNO
               AND LPEDORITEM.CONTNO = LCCONT.CONTNO)
     GROUP BY B, C;