#select min(issue_time) from voucher_issued_details_for_report set @start_time = '2020-05-01 00:00:00'; set @end_time = '2020-05-31 23:59:59'; #get opening select SUM( IF(issue_time < @start_time, voucher_value, 0 )) - SUM( IF(reimburse_time < @start_time, voucher_value, 0 )) - SUM( IF(void_time < @start_time, voucher_value, 0 )) AS 'Opening Floating', SUM( IF(issue_time between @start_time and @end_time, voucher_value, 0 )) as issued, SUM( IF(reimburse_time between @start_time and @end_time, voucher_value, 0 )) as reimbursed, SUM( IF(void_time between @start_time and @end_time, voucher_value, 0 )) as void, SUM( IF(expire_time between @start_time and @end_time, voucher_value, 0 )) as expired from voucher_issued_details_for_report;
月度归档: 2020年6月
Merctus use snapshot table calculate voucher summary report
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)