Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 22, 2020 03:19
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/99bb0484c84e6cc9fcb66010663359f0 to your computer and use it in GitHub Desktop.
Save parzibyte/99bb0484c84e6cc9fcb66010663359f0 to your computer and use it in GitHub Desktop.
MariaDB [attendance]> select employee_id,
-> 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
-> group by employee_id;
+-------------+----------------+---------------+
| employee_id | presence_count | absence_count |
+-------------+----------------+---------------+
| 2 | 4 | 3 |
| 3 | 6 | 1 |
+-------------+----------------+---------------+
2 rows in set (0.000 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment