我有一组数据,每隔5或15分钟告诉我几个系统是否可用。目前,时间间隔不重要。
数据看起来像这样:
Status Time System_ID
T 10:00 S01
T 10:15 S01
F 10:30 S01
F 10:45 S01
F 11:00 S01
T 11:15 S01
T 11:30 S01
F 11:45 S01
F 12:00 S01
F 12:15 S01
T 12:30 S01
F 10:00 S02
F 10:15 S02
F 10:30 S02
F 10:45 S02
F 11:00 S02
T 11:15 S02
T 11:30 S02
我希望创建一个视图,用于指示系统何时不可用(即为F),从什么时间到什么时间以及持续时间(即“至 - 从”)。
期望的结果:
System_ID From To Duration
S01 10:30 11:00 00:30
S01 11:45 12:15 00:30
S02 10:00 11:00 01:00
以下是脚本数据:
DROP SCHEMA IF EXISTS Sys_data CASCADE;
CREATE SCHEMA Sys_data;
CREATE TABLE test_data (
status BOOLEAN,
dTime TIME,
sys_ID VARCHAR(10),
PRIMARY KEY (dTime, sys_ID)
);
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '10:00:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '10:15:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '10:30:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '10:45:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '11:00:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '11:15:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '11:30:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '11:45:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '12:00:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '12:15:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '12:30:00', 'S01');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '10:00:00', 'S02');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '10:15:00', 'S02');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '10:30:00', 'S02');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '10:45:00', 'S02');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (FALSE, '11:00:00', 'S02');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '11:15:00', 'S02');
INSERT INTO test_data (status, dTime, sys_ID) VALUES (TRUE, '11:30:00', 'S02');
感谢您的提前帮助!