行之间的sqlite差异

sqlite difference between rows

在 SQLite 中,我有一个记录集合,我只想显示具有特定差异的记录。

table 具有类似于以下值的内容: file | idx | values ------|-------|---------------------- 1 | 101 | 1,3,7,11,23,11 2 | 101 | 1,3,7,11,23,11 3 | 101 | 0,4,8,60,20,11 1 | 211 | 12,11,23 2 | 211 | 12,0,23 3 | 211 | 12,0,23 1 | 300 | 1 2 | 300 | 0 3 | 300 | 0

我希望能够 select 两个不同的文件 ID,并比较它们。 我的意思是,我只想检查 (file = 1 AND file = 2)

的记录

结果我无法取回的是一组不同的记录:
file | idx | values ------|-------|---------------------- 1 | 211 | 12,11,23 2 | 211 | 12,0,23 1 | 300 | 1 2 | 300 | 0

因此您不希望存在具有相同 idxvalues 值的另一行的行:

SELECT *
FROM MyTable
WHERE file IN (1, 2)
  AND NOT EXISTS (SELECT *
                  FROM MyTable AS T2
                  WHERE file IN (1, 2)
                    AND file   <> MyTable.file
                    AND idx    =  MyTable.idx
                    AND values =  MyTable.values);

我刚刚在另一个论坛上收到了答案。这似乎有效:

select * from thetable a, thetable b where a.file <> b.file and a.idx = b.idx and a.values <> b.values and a.file in (1, 2) and b.file in (1, 2);

当然,我在准备好的语句中将某些值更改为变量。但它成功了