Skip to content
Advertisement

Is there a way in SQL Server to sequence data by a group? [closed]

I have a table of data that has the following columns

The data is going into a timeclock system. I am ultimately trying to find a way to sequence the data by employee because my output needs to look like this.

The problem is that there is no easy way to tell how many entries per employee there could be in a day. These are bus drivers so they clock in and out for their morning route, afternoon route, and possibly even fieldtrips in the middle. Plus what happens if they miss a punch and now have an uneven number of rows.

Anyway I am trying to get the following example as my input and output.

I am very new to SQL so I don’t even know if it’s possible but appreciate the help!

Advertisement

Answer

id date date2
12345 2022-08-25 08:45:00.000 2022-08-25 09:45:00.000
12345 2022-08-25 13:00:00.000 2022-08-25 13:30:00.000
23456 2022-08-25 10:00:00.000 2022-08-25 11:00:00.000

Fiddle

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement