select
substr(a.date,1,7) as date_month -- yyyy-MM
,sum(b.数据) as data_num -- 月累计
from table1 a
left join table1 b on a.date >= b.date
where substr(a.date,1,7) = substr('${date_time}',1,7) and a.date <= '${date_time}'
group by substr(a.date,1,7)
--
年累计改下where后面的条件就好了
select
substr(a.date,1,4) as date_month -- yyyy
,sum(b.数据) as data_num -- 年累计
from table1 a
left join table1 b on a.date >= b.date
where substr(a.date,1,7) = substr('${date_time}',1,4) and a.date <= '${date_time}'
group by substr(a.date,1,4)