2015-11-03 81 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;