2

我有一张类似的桌子。

creation_time           po_S            count_out_I
2012-08-03 02:45:02.133 000002029382    15974
2012-08-03 02:48:02.083 000002029382    9475
2012-08-03 02:51:02.097 000002029382    15978
2012-08-03 02:54:02.120 000002029382    15990

当按creation_time排序时,我需要找到count_out_I小于上一行的行。数据库是 SQL Server 2008。感谢帮助。

4

1 回答 1

4

这将报告第一行递减count_out_I

; with  numbered as
        (
        select  row_number() over (order by creation_time) as rn
        ,       *
        from    YourTable
        )
select  top 1 cur.*
from    numbered cur
join    numbered prev
on      prev.rn + 1 = cur.rn
where   cur.count_out_I < prev.count_out_I
order by
        cur.rn
于 2012-08-06T12:08:36.050 回答