SELECT *
FROM (SELECT 字段,MAX(CAAOUNTING_TIME) AS CAAOUNTING_TIME
WHERE 1=1
${IF(LEN(截止日期)=0,"","AND REPLACE(CAAOUNTING_TIME,'-','')<=REPLACE('"+截止日期+"','-','')")}
GROUP BY 字段) A
WHERE 1=1
${IF(LEN(截止日期)=0,"","AND REPLACE(CAAOUNTING_TIME,'-','')>=COUNT_WS('',LEFT('"+截止日期+"',4),'01')")}