SELECT CPBB.BRAND_NO,cpbb.BRAND_NAME,qq.DECISION,qdr.DEFECTIVE_REASONS_NO,qdr.DEFECTIVE_REASONS_DESC, ${IF(sumtype='0',"","to_char(qq.CREATE_TIME,'YYYY-MM') rq,")} ${IF(sumtype='1',"","to_char(qq.CREATE_TIME,'YYYY-MM-DD') rq,")} sum(qq.INSPECTION_QTY) unq FROM WIP_RUNCARD_STATUS_LOG wrsl LEFT JOIN QCM_QC qq ON qq.WIP_MO_LOT_GUID = wrsl.MO_DOC_GUID_FROM AND qq.DELETE_FLAG = 'N' LEFT JOIN QCM_QC_D qqd ON qqd.FROM_GUID = qq.guid AND qqd.DELETE_FLAG = 'N' LEFT JOIN WMS_ITEM_DETAIL wid ON wid.guid = wrsl.ITEM_GUID LEFT JOIN WIP_MO_DOC wmd ON wmd.GUID = qq.WIP_MO_LOT_GUID LEFT JOIN CPP_PRD_BRAND_BAS cpbb ON cpbb.guid = wmd.brand_guid LEFT JOIN QCM_DEFECTIVE_REASONS qdr ON qdr.guid = qqd.QCM_DREASONS_GUID WHERE qq.DECISION='2' AND qqd.QCM_DREASONS_GUID IS NOT null GROUP BY CPBB.BRAND_NO,cpbb.BRAND_NAME,qq.DECISION,qdr.DEFECTIVE_REASONS_NO,qdr.DEFECTIVE_REASONS_DESC ${IF(sumtype='0',"",",to_char(qq.CREATE_TIME,'YYYY-MM')")} ${IF(sumtype='1',"",",to_char(qq.CREATE_TIME,'YYYY-MM-DD')")} 问题说明:我加了一个参数sumtype,根据传参不同产生不同的统计数据。 sumtype=0,按月统计 sumtype=1,按日统计 但是在SQL预览时, 输入参数0,显示的是按日统计的数据, 输入参数1,显示的是按月统计的数据。 |