1
当运行这个查询:如何在postgresql中将时间间隔转换为十进制值?
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。
非常感谢!
'SELECT ...,提取物(从时代END_DATE-起始日期)/(24 * 60 * 60) as timediff FROM content_events;'[Doc](https://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT) – Abelisto
您确定该版本?.. –
@ VaoTsun是的,这就是我得到的:版本 PostgreSQL 8.0.2在i686-pc-linux-gnu上编译b y GCC gcc(GCC)3.4.2 20041017(Red Hat 3.4.2-6.fc3),Redshift 1.0.1232 – Henry