Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created Nov 22, 2020
Embed
What would you like to do?
<?php
function getEmployeesWithAttendanceCount($start, $end)
{
$query = "select employees.name,
sum(case when status = 'presence' then 1 else 0 end) as presence_count,
sum(case when status = 'absence' then 1 else 0 end) as absence_count
from employee_attendance
inner join employees on employees.id = employee_attendance.employee_id
where date >= ? and date <= ?
group by employee_id;";
$db = getDatabase();
$statement = $db->prepare($query);
$statement->execute([$start, $end]);
return $statement->fetchAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment