I want to get count of people who leave on time in some specific date range in an attendance scenario. For that I need total employees who marked their attendance when they left office. If an employee logged at-least two times (1 for in and 2nd for out) only then he should be counted in total employees who marked their out attendance.
SELECT Max(TIMESTAMP),COUNT(DISTINCT employee_id) totalCount FROM attendance , db2.psnl p WHERE Date(timestamp) BETWEEN STR_TO_DATE('14/05/2019', '%d/%m/%Y') AND STR_TO_DATE('14/05/2019', '%d/%m/%Y') AND employee_id=p.MyId AND p.PayRollOfficeId=3 GROUP BY DATE(TIMESTAMP) HAVING COUNT(employee_id) >=2
For a single employee a modified version of this query works as group by filters the employee and so count >=2 will return rows when we have at-least 2 entries against employee for any date.