1

Im getting interval times via:

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

This returns a table like this:

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

I want to have the time in seconds like this:

 38
 310
 125
 ...

Here is my approach:

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

dt should be the table with the difference times (intervals). However I get the following error:

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

So I have to cast record (the table 'dt') to interval? How do I do that? Or is this completely wrong? Sorry Im new to database queries....

4

1 回答 1

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
于 2013-05-22T14:44:13.500 回答