2015-11-03 77 views
-4

兩個連續行(不是日期時間數據類型)之間的差異。postgresql中兩個連續行之間的差異

select cast (max( tb1 a ) as integer), 
cast (min( tb1 a ) as integer) 
from tb1 where tb2 c in (select Id from tb2 where tb3 c1 =566) 
group by tb2 c  
order by tb2 c desc 
limit 2 
offset 0 

你可以糾正它。

在這裏可以使用Windows功能?

+0

請編輯您的問題。這很難閱讀,說實話,很難說出你的要求。 –

回答

0

如果要查找成功行之間的差異,請使用leadlag窗口函數。該文檔包含示例,並且已經有很多關於Stack Overflow的示例。

通常它看起來是這樣的:

select id, the_col - lag(the_col) OVER (ORDER BY id) 
from my_table;