运行此查询时:
SELECT
start_date,
end_date,
end_date-start_date as timediff
FROM content_events
我得到这样一张桌子:
+---------------------+---------------------+-----------------+
| start_date | end_date | timediff |
+---------------------+---------------------+-----------------+
| 2017-03-23 23:00:00 | 2017-04-01 22:00:00 | 8 days 23:00:00 |
+---------------------+---------------------+-----------------+
但我想得到这样的东西:
+---------------------+---------------------+-----------------+
| start_date | end_date | timediff |
+---------------------+---------------------+-----------------+
| 2017-03-23 23:00:00 | 2017-04-01 22:00:00 | 8,96 |
+---------------------+---------------------+-----------------+
请注意,我只需要将时差作为带有两位小数的数值。
我正在使用PostgreSQL 8.0.2。
非常感谢!
答案 0 :(得分:1)
这个select
语句可以正常工作:
(date_part(epoch,end_date)::float - date_part(epoch,start_date)::float)/(24*60*60) as timediff
或者这个:
(extract(epoch from end_date)::float - extract(epoch from start_date)::float)/(24*60*60) as timediff