WHERE
1=1
AND cmonth = to_char(to_date('${period}', 'yyyy-mm') - interval '1 month', 'yyyymm');
最后的分号不要
你是什么数据库
SQLSERVER: SELECT FORMAT(DATEADD(MONTH, -1, '2024-06-20'), 'yyyy-MM') AS PreviousMonth
MYSQL:
SELECT DATE_FORMAT(DATE_SUB('2024-06-20', INTERVAL 1 MONTH), '%Y-%m') AS PreviousMonth