我正在寻找一种方法来绘制一个玩具店男孩正在检查他的工作的时间。整个图表会有一个明确的开始和结束时间,但是要考虑他/她在工作上花费的时间。
实际的数据库只会让男孩检查工作的时间和他/她的时间。例如:
employerID | start_time | end_time
---------------------------------------------
1 | 2014-12-10 09:00:00 | 2014-12-10 09:37:00
1 | 2014-12-10 09:53:00 | 2014-12-10 11:44:00
1 | 2014-12-10 12:00:00 | 2014-12-10 15:00:00
提取数据并导入(??)之后,我的IDEAL图输出看起来像
我知道PSGL不能单独完成这项工作但不确定我是否需要以任何特殊格式构建数据来计算X距离(类似于年龄(end_time,start_time)等)。
提前感谢您的帮助!
答案 0 :(得分:0)
在PostgreSQL中,您可以减去时间戳。
select employer_id, start_time, end_time, end_time - start_time as elapsed_time
from timeshifts;
employer_id start_time end_time elapsed_time -- 1 2014-12-10 09:00:00-05 2014-12-10 09:37:00-05 00:37:00 1 2014-12-10 09:53:00-05 2014-12-10 11:44:00-05 01:51:00 1 2014-12-10 12:00:00-05 2014-12-10 15:00:00-05 03:00:00
Excel是否可以识别“elapsed_time”中的值是另一回事。在Excel中进行减法可能更容易。
create temp table timeshifts (
employer_id integer not null,
start_time timestamp with time zone not null,
end_time timestamp with time zone not null,
check (start_time < end_time),
primary key (employer_id, start_time)
);
insert into timeshifts values
(1, '2014-12-10 09:00:00', '2014-12-10 09:37:00'),
(1, '2014-12-10 09:53:00', '2014-12-10 11:44:00'),
(1, '2014-12-10 12:00:00', '2014-12-10 15:00:00');