psql日期和实际问题
我的psql数据库中有一个查询,但我有一个小问题:psql日期和实际问题,sql,postgresql,Sql,Postgresql,我的psql数据库中有一个查询,但我有一个小问题: select sge_job.j_id, sge_job_usage.ju_id, sge_job_usage.ju_slots, date_trunc ('hour',sge_job_usage.ju_start_time) – date_trunc ('hour',sge_job.j_submission_time) as "Wait time" from sge_job, sge_job
select sge_job.j_id,
sge_job_usage.ju_id,
sge_job_usage.ju_slots,
date_trunc ('hour',sge_job_usage.ju_start_time) – date_trunc ('hour',sge_job.j_submission_time) as "Wait time"
from sge_job,
sge_job_usage
where sge_job.j_id = sge_job_usage.ju_id
and sge_job_usage.ju_start_time >= sge_job.j_submission_time
问题是我在ju开始时间和j_提交时间获得的信息将在小时格式内保留,但其中一些人的信息是3天12小时
它们都是没有时区的时间戳,但我需要它来计算是否为2天,并将它们添加到小时中。所以我现在的输出是:
71 | 71 | 1 | 01:00:00
72 | 72 | 1 | 01:00:00
73 | 73 | 2 | 4 days 03:00:00
74 | 74 | 2 | 01:00:00
75 | 75 | 2 | 03:00:00
76 | 76 | 2 | 03:00:00
77 | 77 | 1 | 22:00:00
78 | 78 | 1 | 18:00:00
79 | 79 | 2 | 19:00:00
80 | 80 | 2 | 20:00:00
81 | 81 | 2 | 20:00:00
82 | 82 | 2 | 11:00:00
83 | 83 | 2 | 21:00:00
84 | 84 | 2 | 1 day 10:00:00
85 | 85 | 2 | 1 day 17:00:00
86 | 86 | 2 | 2 days 17:00:00
因此,随着date_trunc hour,它将我的时间格式更改为多少小时,但我似乎无法获得一个函数,将我的天数转换为小时格式,因此我希望86的列为48小时(2天)+17=65小时,作为结果,有什么建议吗?提前感谢从另一个时间戳中减去一个时间戳会产生一个间隔值。您必须将该时间间隔转换为小时才能显示 要将时间间隔转换为(例如)小时,请使用以下命令:
extract(epoch from <interval_value>) / 3600
非常感谢,工作正是我现在需要的
extract(epoch from date_trunc('hour',sge_job_usage.ju_start_time) – date_trunc ('hour',sge_job.j_submission_time)) / 3600 as "Wait time"