我想计算redshift中两个日期之间的天数,但是如果日期之间的时间少于24小时(例如MySQL中的Timestampdiff函数),则该函数应考虑平均日= 0的时间。 Datediff与此无关。
答案 0 :(得分:3)
执行DATEDIFF(hours, start, end) / 24
计算小时数,然后除以24得到整天的数量,例如:
db=# create table t (a TIMESTAMP, b TIMESTAMP);
CREATE TABLE
db=# insert into t values ('2015-08-19 03:56:39'::timestamp, '2015-08-23 02:22:18'::timestamp);
INSERT 0 1
db=# insert into t values ('2015-08-19 03:56:39'::timestamp, '2015-08-23 10:22:18'::timestamp);
INSERT 0 1
db=# select a, b, datediff(hours, a, b) / 24 as whole_days from t;
a | b | whole_days
---------------------+---------------------+------------
2015-08-19 03:56:39 | 2015-08-23 02:22:18 | 3
2015-08-19 03:56:39 | 2015-08-23 10:22:18 | 4
(2 rows)
另见: