Top N earliest punched in Employees across departments in a month
1
vote
1
answer
37
views
Find two of the earliest punched in Employees across departments in a month The dataset.
Id EmpName EmpPunchInTime EmpDept
1 Dharma 26-JAN-2018 08:45 Engineering
2 Gumpina 26-JAN-2018 08:46 Finance
3 Kumar 26-JAN-2018 08:47 HR
4 Kamal 26-JAN-2018 08:48 Engineering
5 Muruges 26-JAN-2018 08:49 Finance
6 Gumpina 25-JAN-2018 09:01 Finance
7 Kumar 25-JAN-2018 08:42 HR
8 Biju 25-JAN-2018 08:40 Engineering
9 Divya 25-JAN-2018 08:49 HR
10 Vali 24-JAN-2018 08:52 Engineering
The expected output is,
Id EmpName EmpPunchInTime EmpDept
8 Biju 25-JAN-2018 08:40 Engineering
1 Dharma 26-JAN-2018 08:45 Engineering
2 Gumpina 26-JAN-2018 08:46 Finance
5 Muruges 26-JAN-2018 08:49 Finance
7 Kumar 25-JAN-2018 08:42 HR
9 Divya 25-JAN-2018 08:49 HR
FYI I the query which I used
SELECT *
FROM (SELECT *
,DENSE_RANK() OVER ( PARTITION BY EmpDept ORDER BY EmpPunchInTime) RANK
FROM EMPLOYEE_PUNCH) emp_pun
WHERE RANK <= 2
I have tried to solve by using dense rank(partition by EmpDept, order by EmpPunchInTime) but am not seeing desired results.
*Note: If the same employee in a department punches early in most of the days(like Kumar of HR dept here in this dataset) then pick the earliest date among his dates and the employee who punches next to him.*
Asked by Lakshmana Gumpina
(13 rep)
Aug 1, 2018, 01:36 PM
Last activity: Aug 1, 2018, 02:32 PM
Last activity: Aug 1, 2018, 02:32 PM