I am having SQL table where the records of the employee on daily basis are stored/saved I would like to get that result in tabular format
Consider a Table As Shown Below
I had used a CTE which is worked for me and is as follows
WITH cte
AS (SELECT Row_number()
OVER(
partition BY [name]
ORDER BY [name]) AS rn, *FROM table1)
SELECT a.[dateandtime] AS [IN],
b.[dateandtime] AS [OUT],
a.[action] AS [myaction],
c.[dateandtime] AS [lunchTIME]
FROM (SELECT *
FROM cte a
WHERE rn = 1) a
JOIN (SELECT *
FROM cte b
WHERE rn = 2) b
ON a.[name] = b.[name]
LEFT JOIN (SELECT *
FROM cte b
WHERE rn = 3) c
ON a.[name] = c.[name]