0

我需要知道具有相同值的连续行

在此处输入图像描述

我需要prsstatus值为 0 的行,然后下一行是 1

4

2 回答 2

1

假设您的意思是“下一个”行的密集值TblID

select YTN.*
from YourTableName as YTN inner join
   YourTableName as NR on NR.TblID = YTN.TblId + 1 and
     NR.PrsStatus = 1 and YTN.PrsStatus = 0
于 2013-10-06T02:44:50.863 回答
1

另一种方法,将 MyTable 更改为您的表,并将ORDER BY子句更改为您想要排序的任何列。

;WITH  MyTableSort AS (
    SELECT TblID, EmpID, PrsDay, PrsTime, PrsStatus, ROW_NUMBER() OVER (ORDER BY MyTable.TblID) [Row] FROM MyTable
)
SELECT * FROM MyTableSort AS MyTableSortA 
WHERE (MyTableSortA.PrsStatus = 0 AND EXISTS (SELECT 1 FROM MyTableSort WHERE MyTableSort.[Row] = MyTableSortA.[row]+1 AND MyTableSort.PrsStatus = 1)) 
于 2013-10-06T02:57:28.513 回答