SQL question
Question
Suppose a employee timesheet table is given, which has attributes emp_id, emp_status (IN/OUT only), swipe_time(which records date and time both when the card is swiped). Write a SQL query to find total number of employees who are inside the office at 4PM . Consider all possible cases .
in progress
0
SQL
55 years
1 Answer
1150 views
0
Answer ( 1 )
A similar question was asked in Meesho for a Business Analyst role.
SELECT
SUM(CASE WHEN emp_status = ‘In’ THEN 1
WHEN emp_status = ‘Out’ THEN -1)
FROM emp_timesheet
WHERE swipe_time < '16:00:00' AND emp_status = 'Out'