I have an attendance table included wfo/wfh records and also have employees table too. I want to count is the employee working from home or office on every date, for every month. I need to join it to employees table too, to count those employees from all cities except 2. Can you guys please help constructed it? Thank you..
SELECT b.created_at,
COUNT(CASE WHEN b.is_wfh = 'true' THEN 1 ELSE NULL END) AS 'WFH',
COUNT(CASE WHEN b.is_wfh = 'false' THEN 1 ELSE NULL END) AS 'WFO'
FROM attendancetable b
JOIN employeetable a ON a.id = b.id
WHERE b.created_at BETWEEN '2022-01-01' AND '2022-01-31'
AND a.office_location NOT LIKE '%D%' AND a.office_location NOT LIKE '%E%'
sorry I'm not that good with english. here's the example
employee table
name employee_id office_location
======================================
Happy 1 A
Sad 2 B
Angry 3 C
Hungry 4 D
Grumpy 5 E
attendance table
employee_id created_at is_wfh
======================================
1 2022-01-01 true
2 2022-01-01 true
3 2022-01-01 false
4 2022-01-01 false
5 2022-01-01 false
1 2022-01-02 false
2 2022-01-02 true
3 2022-01-02 false
4 2022-01-02 true
... ... ...
expected (count wfh and wfo) result with conditions: employee from A, B, C only AND date between 2022-01-01 and 2022-01-31
created_at wfh wfo
============================
2022-01-01 2 1
2022-01-02 1 2
I hope my explanation is enough.. thankyou! ...
Sorry I wanna ask more question. If there's time record at created_at field, what should I do to combine all those counting of wfh/wfo?