参考看一下
SELECT
'面积' 类型1,
'月面积' 类型2 ,
B.cFactoryType,
CONCAT(IYEAR,A.iPeriod) iYearMonth ,
${if(len(大类)=0,"''","A.cInvSaleClass" )} as cInvSaleClass,
sum(case when ( ISTAGE<${if(len(zq1)=0,0,zq1)}) then A.iQty_Area END) zq1 ,
sum(case when ISTAGE>=${if(len(zq1)=0,0,zq1)} and ISTAGE<${if(len(zq2)=0,0,zq2)}then A.iQty_Area END) zq2 ,
sum(case when ISTAGE>=${if(len(zq2)=0,0,zq2)} and ISTAGE<${if(len(zq3)=0,0,zq3)}then A.iQty_Area END) zq3 ,
sum(case when ISTAGE>=${if(len(zq3)=0,0,zq3)} and ISTAGE<${if(len(zq4)=0,0,zq4)}then A.iQty_Area END) zq4 ,
sum(case when ISTAGE>=${if(len(zq4)=0,0,zq4)} and ISTAGE<${if(len(zq5)=0,0,zq5)}then A.iQty_Area END) zq5 ,
sum(case when ISTAGE>=${if(len(zq5)=0,0,zq5)} and ISTAGE<${if(len(zq6)=0,0,zq6)}then A.iQty_Area END) zq6 ,
sum(case when ISTAGE>=${if(len(zq6)=0,0,zq6)} and ISTAGE<${if(len(zq7)=0,0,zq7)}then A.iQty_Area END) zq7 ,
sum(case when ISTAGE>=${if(len(zq7)=0,0,zq7)} and ISTAGE<${if(len(zq8)=0,0,zq8)}then A.iQty_Area END) zq8 ,
sum(case when ISTAGE>=${if(len(zq8)=0,0,zq8)} then A.iQty_Area END) zq9
FROM DWS_Inv_CurrentStockAge_MD A
LEFT JOIN DM_FactoryInfo B ON A.cFactoryCode=B.cFactoryCode
WHERE LEN(B.cFactoryType)>0
and LEN(A.cInvSaleClass)>0
AND CONCAT(IYEAR,A.iPeriod)='${p_date}'
${if(len(p_dl)=0,""," and A.cInvSaleClass in ('"+p_dl+"')")}
GROUP BY B.cFactoryType,IYEAR,A.iPeriod ${if(len(大类)=0,"",",A.cInvSaleClass" )}