postgresql 两行数据时间之差

//获取两行之间的时间差,并转换成分钟

1 select *,extract(epoch from((aaa."ar"::timestamp) - (bbb."br"::timestamp)))/60 as counterDiffer from 
2 (select row_number() OVER (ORDER BY "ID") as aa,"ReceiveTime" as ar from public."YourTableName" where "searchID" = '123456') as aaa,
3 (select row_number() OVER (ORDER BY "ID") as bb,"ReceiveTime" as br from public."YourTableName" where "searchID" = '123456') as bbb 4 where aa -1 =bb order by ar

 

posted @ 2020-01-20 21:41  indexlang  阅读(1431)  评论(0编辑  收藏  举报