I am working on a SQL Server query to fetch the last Badge_In_Out_Time of the list of users who will be working on multiple task codes.
task_mgmt - tablename
Table Columns as follows
| Task_Sn | UserName | Task_Code | Action | Badge_IN_OUT_TIME |
|---|---|---|---|---|
| 1 | Andy | BLOG | START | 2021-07-15 08:11:45.000 |
| 2 | Andy | BLOG | END | 2021-07-15 10:11:45.000 |
| 3 | Becky | ACCTS | START | 2021-07-15 11:11:45.000 |
| 4 | Chris | TAX | START | 2021-07-15 12:11:45.000 |
| 5 | Andy | SOCMEDIA | START | 2021-07-15 12:15:45.000 |
| 6 | Becky | ACCTS | END | 2021-07-15 12:25:45.000 |
I am excepting the result
| UserName | Task_Code | Badge_IN_TIME | Badge_OUT_TIME |
|---|---|---|---|
| Andy | BLOG | 2021-07-15 08:11:45.000 | 2021-07-15 10:11:45.000 |
| Becky | ACCTS | 2021-07-15 11:11:45.000 | 2021-07-15 12:25:45.000 |
| Chris | TAX | 2021-07-15 12:11:45.000 | |
| Andy | SOCMEDIA | 2021-07-15 12:15:45.000 |
I really couldn't come up with any query for this. I am a beginner in SQL and I know CRUD operations. This seems to be super complex for me.
Select UserName, Task_Code, Badge_In_Time, Badge_Out_Time from task_mgmt order by Badge_IN_OUT_TIME desc