select trim(GBOBJ)||trim(GMSUB) a, 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 from proddta.f0902,proddta.f0901 where GMAID = GBAID and GBCTRY = '${GBCTRY}' and GBFY = '${GBFY}' and GBCO = '${GBCO}' order by a desc 这是我求本年累计金额总和的SQL 比如我选择18年6月份 报表模板就来16年的总和 17年的总和 到18年 就是1+2+.....+6月的总和 求问模板怎么设计 SQL如何改一下 |