Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 22, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/bcfaaa9e08f9294ae1cbd49d57a46e6e to your computer and use it in GitHub Desktop.
Save parzibyte/bcfaaa9e08f9294ae1cbd49d57a46e6e to your computer and use it in GitHub Desktop.
<?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