select name, isSalesRep, extension, cast(CONCAT(YEAR(`date`), '-', month(`date`), '-', day(`date`)) as date) as ymd, sum(if(caller_id like '%no answer%', 1, 0)) as no_answer, sum(1) as total_in, (sum(if(caller_id like '%no answer%', 1, 0)) / sum(1)) as miss_call_rate from phone.transaction as t left join phone.extension as e on (e.code = t.extension) where t.`date` >= cast(adddate(date_format(CURDATE() - INTERVAL 2 WEEK,'%Y-%m-%d 00:00:00'), 1 - dayofweek(date_format(CURDATE() - INTERVAL 2 WEEK,'%Y-%m-%d 00:00:00'))) as datetime) and class in ('IVIN', 'PTRS') and extension <> '' and exclude = 0 and (e.id is null or e.isSalesRep = 1) and (duration <> '00:00:00' or length(phone_number) >= 7) group by extension, ymd order by extension, ymd