你的业务表如果有日期,直接where限制上月25号到本月24日查询就可以了(你的难点在哪里不太清楚)
或者
弄一个日期维度度。。。。。就是比如说你有一个表是10年的每一天的日期都在里面,然后用这个表做为主表去关联你的数据就可以了。。。最后再where 限制一下数据取上月25到本月24日不就可以了
where 1=1
and date_time >='${date(year(today()),month(today())-1,25)}'
and date_time <='${date(year(today()),month(today()),24)}'
会按系统的日期自动查询上月25到本月24号的数据。。支持跨年。。。
------------------我是分隔符号-------------------
select
t.mydate,
t.value_s,
date_format( ADDDATE(ADDDATE(t.mydate,INTERVAL - 24 DAY ),INTERVAL 1 MONTH ),'%Y-%m') AS 判断后的年月
from (
select '2021-03-23' as mydate,72 as value_s union all
select '2021-03-24' as mydate,69 as value_s union all
select '2021-03-25' as mydate,72 as value_s union all
select '2021-03-26' as mydate,78 as value_s union all
select '2021-03-27' as mydate,39 as value_s union all
select '2021-03-28' as mydate,34 as value_s union all
select '2021-03-29' as mydate,66 as value_s union all
select '2021-03-30' as mydate,37 as value_s union all
select '2021-03-31' as mydate,74 as value_s union all
select '2021-04-01' as mydate,34 as value_s union all
select '2021-04-03' as mydate,38 as value_s union all
select '2021-04-24' as mydate,38 as value_s union all
select '2021-04-25' as mydate,997 as value_s union all
select '2021-04-27' as mydate,21 as value_s union all
select '2021-05-24' as mydate,391 as value_s union all
select '2021-05-25' as mydate,391 as value_s
) t