WITH cte
AS ( SELECT
--ROW_NUMBER() OVER ( PARTITION BY StuID ORDER BY BZList.BZInputTime ) pid,
BZDate, BZInputTime, StuName, STUID, BZKTypeName,
BZData
FROM BZList
WHERE StuID = 26768
AND ( ( BZKTypeName = '桩考'
AND BZInfro = '不及'
)
OR ( BZKTypeName = '补考名单'
AND BZData = '桩考'
)
)
-- ORDER BY BZList.BZInputTime
)
SELECT BZDate, BZInputTime, StuName, STUID, BZKTypeName, BZInputTime1
FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY stuid, s2.BZInputTime ORDER BY BZInputTime DESC ) PID,
*
FROM ( SELECT s0.BZDate, s0.BZInputTime, s0.StuName,
s0.STUID, s0.BZKTypeName,
BZInputTime1 = s1.BZInputTime
FROM ( SELECT BZDate, BZInputTime, StuName,
STUID, BZKTypeName, BZData
FROM cte
WHERE BZKTypeName = '桩考'
) s0
JOIN ( SELECT BZDate, BZInputTime,
StuName, STUID,
BZKTypeName, BZData
FROM cte
WHERE BZKTypeName = '补考名单'
) s1 ON s0.stuid = s1.stuid
AND s0.BZInputTime < s1.BZInputTime
) s2
) s3
WHERE pid = 1
SELECT BZDate, BZInputTime, StuName, STUID, BZKTypeName, BZData
FROM BZList
WHERE StuID = 26768
AND ( ( BZKTypeName = '桩考'
AND BZInfro = '不及'
)
OR ( BZKTypeName = '补考名单'
AND BZData = '桩考'
)
)
ORDER BY BZList.BZInputTime