${if(len(col)=0,'*',replace(col,'count','sum(count)'))}
如果我有多个字段需要合计,需要怎么写当参数col不为空,“abc,count,jin”只把count 转换成 sum(count),我还需要把 jin 也转换成 sum(jin)
需要怎么写 这个。
${if(len(col)<1,"","group by "+replace(col,',count',''))}
后面这个GROUP BY 也需要怎么写
SELECT ${if(len(col)==0,"*",REPLACE(REPLACE(col,"count","SUM(count) as 'sum_count'"),"jin","SUM(jin) as 'sum_jin'"))} FROM STSCORE ${if(len(col)==0,"",CONCATENATE("GROUP BY ",REPLACE(REPLACE(col,",count",""),",jin","")))}
完全可以一个个分开写,不用弄很绕的replace,看起来更清晰
select
${if(len(col)=0,'abc','abc')}
,
${if(len(col)=0,'count','sum(count)count')}
${if(len(col)=0,'jin','sum(jin) jin')}
from xxx -- 当然第一个abc不变化可以直接省了不用公式
group by 也是一样了
SELECT sj as date_time,
${if(len(BU)=0,"--","BU,")}
${if(len(TYPE_TREE)=0,"--","'class' as class,")}
${if(len(stock_type)=0,"--","'stock_type' as stock_type,")}
round(SUM(PNL_QTY),1) AS PNL_QTY,
round(SUM(SUB_QTY),1) AS SUB_QTY,ACT_PLAN
FROM kc_sales_ty_remark
WHERE 1=1
${if(len(BU)==0,"--","") } and BU IN ('${substitute(BU,",","','")}')
and YEAR=TO_CHAR(SYSDATE,'YYYY')
GROUP BY year,sj,ACT_PLAN
${if(len(BU)=0,"--",",BU")}
大概格式就这样。剩下的要根据你的需求来改