select t1.id, t5.name as project,t5.id,IF(t5.multiple="1",t1.name,"") as execution,t2.stories,(t2.stories-t2.undone) as doneStory,t3.number,(t3.number-t3.undone) as doneTask,t4.bugs,t4.resolutions, round(t4.bugs/(t2.stories-t2.undone),2) as bugthanstory,round(t4.bugs/(t3.number-t3.undone),2) as bugthantask,t4.seriousBugs from TABLE_EXECUTION as t1 
left join ztv_projectstories as t2 on t1.id=t2.execution
left join ztv_executionsummary as t3 on t1.id=t3.execution
left join ztv_projectbugs as t4 on t1.id=t4.execution
left join TABLE_PROJECT as t5 on t5.id=t1.project
where t1.deleted='0' and t1.type in ('sprint','stage') and t1.grade='1' and if($project='',1,t5.id=$project) and if($execution='',1,t1.id=$execution)