从间隔表/演员记录中提取秒到间隔?

时间:2013-05-22 14:35:26

标签: postgresql extract

通过以下方式获取间隔时间:

SELECT time_col - lag(time_col) OVER (ORDER BY whatever) 
FROM myTable where conditions

这将返回如下表格:

00:00:38
00:05:10
00:02:05
...

我希望在几秒钟内得到这样的时间:

 38
 310
 125
 ...

这是我的方法:

 SELECT EXTRACT(epoch from dt) from (SELECT time_col - lag(time_col) OVER (ORDER BY whatever) FROM myTable where conditions) as dt

dt应该是具有差异时间(间隔)的表。但是我收到以下错误:

Error:  Function pg_catalog.date_part(unknown, record) does not exist

所以我必须将记录(表'dt')转换为间隔?我怎么做?或者这完全错了?对不起我是数据库查询的新手....

1 个答案:

答案 0 :(得分:1)

这个

SELECT EXTRACT(epoch from dt)
from (
    SELECT time_col - lag(time_col) OVER (ORDER BY whatever) dt
    FROM myTable
    where conditions
) as dt

或者这个

SELECT
    extract(epoch from time_col - lag(time_col) OVER (ORDER BY whatever))
FROM myTable
where conditions