I’m trying to make a monthly report with employee attendance case studies. I have 2 tables which are employee and attendance with the following details:
employee teble
attendance table
after that I created SQL view to display the date column sideways sequentially (with LEFT JOIN function).
monthly_report view
from this view I can display attendance data with a specific month (with WHERE clause)
SELECT
A.employee_id AS id,
A.name,
GROUP_CONCAT(A.1) AS '1',
GROUP_CONCAT(A.2) AS '2',
GROUP_CONCAT(A.3) AS '3',
GROUP_CONCAT(A.4) AS '4',
GROUP_CONCAT(A.5) AS '5',
GROUP_CONCAT(A.6) AS '6',
GROUP_CONCAT(A.7) AS '7'
FROM monthly_report AS A
WHERE MONTH(A.date_time) = '6' AND YEAR(A.date_time) = '2023'
GROUP BY A.employee_id
the problem i have:
I want to display a report by selecting a specific month, and displaying all employee names, but I cannot do this because by using the "where" clause as above, the employee names that appear are the data that carried out activities in that month.
is it possible to display attendance data with a specific month as above, but still display all employee names(like displaying employee name without WHERE clause).
what will the query be like?
Any help appreciated.
2
Answers
I am very happy now. Once again, thank you so much!
final result: enter image description here
Looks like you want to list all employees and show their attendance for a specific month. You need to use an SQL query that combines the employee list with the attendance data for the desired month. If there’s no attendance data for an employee, it should still show the employee’s name with a placeholder, like ‘-‘.
Perhaps something like this:
What’s happening: