just a month Ex.
we can get pre month data and concat to a complate report.
#1.get every monthly data set @start_time = '2020-04-01 00:00:00'; set @end_time = '2020-04-30 23:59:59'; SELECT voucher_id, voucher_value #DATE_FORMAT(expire_time,'%Y%m') months, SUM(voucher_value) AS amount FROM voucher_issued_details_for_report WHERE expire_time >= @start_time AND expire_time <= @end_time and issue_time <= @end_time and (submit_time > @end_time or reimburse_time is null) and (void_time > @end_time or void_time is null) select * from voucher where voucher_id in (1036,1037,5261) select * from voucher_issued_details_for_report where voucher_id in (1036,1037,5261)