select employee_id,  Employee, worked_days as 'Worked Days',  total_num_of_Days - worked_days as 'No.of Leaves Taken',   OverTime from  ( SELECT a.Employee_Id, E.Name as Employee,  sum(case when a.Working_Hours >0 and HalfDay =0 then 1  when a.Working_Hours >0 and HalfDay = 1 then 0.5 else 0 end ) as worked_days ,  case when E.date_of_joining  >= str_to_date('$fromDateTime','%Y-%m-%d') then datediff(str_to_date('$toDateTime','%Y-%m-%d'), date_of_joining) else  datediff(str_to_date('$toDateTime','%Y-%m-%d'), str_to_date('$fromDateTime','%Y-%m-%d')) end as total_num_of_days,  sum(a.Overtime) as OverTime  FROM Attendance_Details a JOIN Employee_Details E ON A.Employee_Id = E._id  WHERE Working_Day >= str_to_date('$fromDateTime','%Y-%m-%d') and Working_Day <= str_to_date('$toDateTime','%Y-%m-%d') group by Employee_Id) X 