2017-02-22 155 views
-1

在SQLite中我有一個記錄集合,我只想顯示具有特定差異的記錄。sqlite行之間的差異

表有類似以下值: 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

我希望能夠選擇兩個不同的fileIDs,並進行比較。 我的意思是,我想只檢查記錄(file = 1 AND file = 2)

我不能回去,結果是不在同一個記錄的集合:
file | idx | values ------|-------|---------------------- 1 | 211 | 12,11,23 2 | 211 | 12,0,23 1 | 300 | 1 2 | 300 | 0

回答

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); 
0

我剛剛收到在另一個論壇的答案。這似乎工作:

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);

當然我改變某些值在一份聲明變量。但它訣竅