#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;