2012-08-06 2 views
2

나는 이와 비슷한 테이블을 가지고 있습니다.SQL은 열의 증가를 멈추는 행을 찾습니다.

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

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 
관련 문제