【问题标题】:sqlite difference between rows行之间的sqlite差异
【发布时间】:2017-02-22 20:37:54
【问题描述】:

在 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

我希望能够选择两个不同的文件 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

【问题讨论】:

    标签: sqlite string-comparison set-difference


    【解决方案1】:

    因此,您不希望存在具有相同 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);
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2011-08-28
        • 2010-09-22
        • 1970-01-01
        • 2018-06-21
        • 1970-01-01
        • 2021-12-27
        • 2015-08-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多