SELECT
*,
(CASE WHEN DATEPART(dd,日期字段) >= 20 THEN DATEADD(MONTH,1,日期字段) ELSE 日期字段 END) AS T_date
FROM
tablename
-------------
-- 其实这个逻辑很好理解,判断日期中DD值,如果大于等于20,月份值+1得到新日期值;然后通过【新日期值】去做其它逻辑即可;
-------------参考上面语法执行;
-------------------------------
select * from
(
SELECT
*,
(CASE WHEN DATEPART(dd,日期字段) >= 20 THEN DATEADD(MONTH,1,日期字段) ELSE 日期字段 END) AS T_date
FROM
tablename
) k
where 1=1
${if(DAY(today())>=20," and CONVERT(VARCHAR(7),T_date,110)="+format(MONTHDELTA(today(),1),"yyyy-MM")," and CONVERT(VARCHAR(7),T_date,110)="+format(today(),"yyyy-MM"))}