Skip to content
Advertisement

Query nanoseconds from first entry

I have a data set keyed with a TestID and a datetime2 value where there are about 8000 entries per TestID, each is about 100 nanoseconds apart.

I’d like to query all rows for a given data set (#40 in this partial example) and return the nanoseconds from the first record. Like this:

I have a query to do it but wonder if there isn’t a better way using a join?

Note – server is SQL Server 2016.

Advertisement

Answer

You can use window functions:

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