WITH INFO AS ( SELECT ${if(WEEK="月","MT.FMONTH AS TMP, ","MT.FWEEK AS TMP, ")} ${if(WEIDU="按班组", "WEH.SHIFT AS TMMP, ",IF(WEIDU="按员工", "WEH.JOCKEY AS TMMP, ",IF(WEIDU="按产品contype","WEH.PRODUCT_TYPE AS TMMP, ", IF(WEIDU="按检验阶段","WEH.INSPECTION_STAGE AS TMMP, ",IF(WEIDU="按浸渍线","WEH.IMPREGNATION_LINE AS TMMP, ","")))))} WEH.HOLE_QUANTITY AS NUM, WEH.MACHINE, WEH.HOLE_AREA FROM MDM_TIME MT LEFT JOIN WR_ET_QUALITY_HOLE WEH ON MT.FYMDAY = WEH.INVESTIGATION_DATE WHERE MT.FYEAR = '${NIAN}' ) SELECT TMP, TMMP, SUM(NUM) AS 数量, MACHINE FROM INFO WHERE 1=1 ${IF(LEN(MUN)=0,"","AND TMP= '"+MUN+"' ")} ${IF(LEN(QUYU)=0,"","AND HOLE_AREA = '"+QUYU+"'")} GROUP BY TMP,TMMP,MACHINE ORDER BY TMP+0 |