コメントで述べたように、 - でタイムスタンプを減算することはできません オペレーター。 DATEDIFF を使用 現在の行と次の行のタイムスタンプの差を取得するには、OUTER APPLY を使用します。 .
select t2._number,t2._timestamp, datediff(microsecond,t2._timestamp,t1._timestamp) as diff from dbo.tbl t2 outer apply (select t1._timestamp from dbo.tcp t1 where t1._number = t2._number + 1) t1プレ>編集:
updateOP のコメントによる diff という名前の列with cte as ( select t2._number,t2._timestamp, t2.diff, datediff(microsecond,t2._timestamp,t1._timestamp) as diff_col from t t2 outer apply (select t1._timestamp from t t1 where t1._number = t2._number + 1) t1 ) update cte set diff=diff_col;プレ>