I have an SQLite DB, let's assume the id can be considered as the order of rows, I want to find repeating sequences in the table according to certain criteria.
consider this example (http://sqlfiddle.com/#!5/dbdb0/1)
schema + data:
CREATE TABLE eventLog
(
id integer primary key autoincrement,
type varchar(20),
details varchar(30)
);
INSERT INTO eventLog
(type, details)
VALUES
('power', 'power on');
INSERT INTO eventLog
(type, details)
VALUES
('cleaner', 'cleaning started');
INSERT INTO eventLog
(type, details)
VALUES
('cleaner', 'cleaning finished');
INSERT INTO eventLog
(type, details)
VALUES
('power', 'power off');
INSERT INTO eventLog
(type, details)
VALUES
('power', 'power on');
INSERT INTO eventLog
(type, details)
VALUES
('cleaner', 'cleaning started');
INSERT INTO eventLog
(type, details)
VALUES
('power', 'power off');
Basic query:
select * from eventLog
order by id asc
I've highlighted some sequences: if I look at repeating sequences in "details" the result should be the ids: [1,2][5,6] and if I look at the "type" column the result should be [[1,2][5,6]],[[3,4][6,7]].
Is there a way to query for repeating sequences without external programing - using SQL only?