Postgresql 赛后时差

Postgresql 赛后时差,postgresql,timestamp,datepart,Postgresql,Timestamp,Datepart,我试图使用postgresql从表(登录历史为t1)中检索以分钟为单位的时差 当我尝试这个代码时 ((date_part('hour', timestamp '2014-04-25 09:44:21')- date_part('hour', timestamp '2014-04-25 08:32:21'))*60 +(date_part('minutes', timestamp '2014-04-25 09:44:21')- date_part('minutes', timestamp '201

我试图使用postgresql从表(登录历史为t1)中检索以分钟为单位的时差

当我尝试这个代码时

((date_part('hour', timestamp '2014-04-25 09:44:21')- date_part('hour', timestamp '2014-04-25 08:32:21'))*60 +(date_part('minutes', timestamp '2014-04-25 09:44:21')- date_part('minutes', timestamp '2014-04-25 08:32:21'))) as TimeNew
它很好用。 但是当我试图使用此代码从表t1检索信息时

((date_part('hour', timestamp t1.login_date)- date_part('hour', timestamp t1.logout_date))*60 +
(date_part('minutes', timestamp t1.login_date)- date_part('minutes', timestamp t1.logout_date))
) as TimeNew
它抛出了这个错误

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "t1"

谢谢

t1
之前,我需要从查询中删除
时间戳
,查询才能工作。

我将使用减去两个时间戳的时间间隔来获得更简单的表达式:

select extract (epoch from (timestamp '2014-04-25 09:44:21' - timestamp '2014-04-25 08:32:21'))::integer/60
(第72页)

或者您的桌子:

select extract (epoch from (t1.logout_date - t1.login_date))::integer/60
如果你需要投:

select extract (epoch from (t1.logout_date::timestamp - t1.login_date::timestamp))::integer/60

或者查看自定义字符串解析的
to_timestamp
函数:

您的计算错误。将第二个时间戳更改为“2014-04-24 08:32:21”,问题将显而易见。首先计算时间间隔,然后将结果分开以分钟表示。