比如 sql查询找到条件1时,结果记录下来,,没有匹配的继续走条件2,再继续匹配条件2的结果,走完了之后,结果记录下来,最后把没有匹配条件1,条件2的 也记录下来 这样查询出的结果就是我需要的 求问怎么写, select case ${GBAN} when 1 then GBAN01/100 when 2 then GBAN02/100 + GBAN01/100 when 3 then GBAN03/100 + GBAN02/100 + GBAN01/100 when 4 then GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 5 then GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 6 then GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 7 then GBAN07/100 + GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 8 then GBAN08/100 + GBAN07/100 + GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 9 then GBAN09/100 + GBAN08/100 + GBAN07/100 + GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 10 then GBAN10/100 + GBAN09/100 + GBAN08/100 + GBAN07/100 + GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 11 then GBAN11/100 + GBAN10/100 + GBAN09/100 + GBAN08/100 + GBAN07/100 + GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 when 12 then GBAN12/100 + GBAN11/100 + GBAN10/100 + GBAN09/100 + GBAN08/100 + GBAN07/100 + GBAN06/100 + GBAN05/100 + GBAN04/100 + GBAN03/100 + GBAN02/100 + GBAN01/100 end as GBAN, trim(GBCO),trim(MCDC),trim(GMOBJ),trim(GMSUB),trim(GMDl01),trim(GBSBL),trim(GBAPYC),trim(MCDC),trim(ABALPH),trim(MCDC)||trim(ABALPH) a FROM PRODDTA.F0902,PRODDTA.F0006,PRODDTA.F0901,PRODDTA.F0101 where gbaid = gmaid and trim(aban8)=trim(gbsbl) --and trim(mcmcu)=trim(gbsbl) and gbco=mcco and mcstyl='BS' and GBCTRY = '${GBCTRY}' and GBFY = '${GBFY}' ${if(len(GBCO)==0,"","and GBCO like '%"+GBCO +"%'")} ${if(len(GMOBJ)==0,"","and GMOBJ like '%"+GMOBJ +"%'")} ${if(len(GMSUB)==0,"","and GMSUB like '%"+GMSUB +"%'")} ${if(len(GBSBL)==0,"","and GBSBL like '%"+GBSBL +"%'")} 标红的就是条件,先满足这个trim(aban8)=trim(gbsbl) ,满足的查询出来,不满足的,继续匹配 trim(mcmcu)=trim(gbsbl)条件,满足的查询出来,这两个条件都不满足的(也就是GBSBL为空的)不满足这两个条件的也同时查询出来 |