我有以下表格结构:
Id,Message 1,John Doe 2,Jane Smith 3,Error 4,Jane Smith
解决方法
;WITH numberedlogtable AS ( SELECT Id,Message,ROW_NUMBER() OVER (ORDER BY ID) AS RN FROM logtable ) SELECT Id,Message FROM numberedlogtable WHERE RN IN (SELECT RN+i FROM numberedlogtable CROSS JOIN (SELECT -1 AS i UNION ALL SELECT 0 UNION ALL SELECT 1) n WHERE Message='Error')