Chr*_*key 2 sql sql-server sql-server-2008
我有一张与此类似的表。
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
Run Code Online (Sandbox Code Playgroud)
我需要找到按creation_time排序时count_out_I小于前一行的行。数据库是 SQL Server 2008。感谢帮助。
这将报告第一行的值递减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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67 次 |
| 最近记录: |