A company record its employees movement In and Out of office in a table with 3 columns
(Employee id, Action (In/Out), Created)
.
First entry for each employee is “In”. Every “In” is succeeded by an “Out". No data gaps and, employee can work across days.
Employee id Action Created
1 In 2019-04-01 12:00:00
1 Out 2019-04-01 15:00:00
1 In 2019-04-01 17:00:00
1 Out 2019-04-01 21:00:00
1.) Find number of employees inside the Office at current time. Below is my attempt.
Select sum(case when Action = 'IN' then 1 when Action = 'OUT' then -1 end) from Company where Created = getdate()