我有一个 SQLite DB,假设 id 可以被视为行的顺序,我想根据某些标准在表中查找重复序列。
考虑这个例子(http://sqlfiddle.com/#!5/dbdb0/1)
架构+数据:
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');
基本查询:
select * from eventLog
order by id asc
我突出显示了一些序列:如果我查看“详细信息”中的重复序列,结果应该是 ids:[1,2][5,6],如果我查看“类型”列,结果应该是 [[ 1,2][5,6]],[[3,4][6,7]]。
有没有一种方法无需外部编程即可查询重复序列 - 仅使用 SQL?