SQLite从表中删除未选择的行

时间:2019-12-18 21:21:03

标签: sqlite

我是SQLite的新手,已经从数据库中选择了我需要的特定行(也就是缺少值的行)。谁能帮助我开发一个查询,该查询将删除所有未选中的行?到目前为止,我可以选择以下内容:

SELECT * FROM BadData_Table   
WHERE A IS NULL OR A = ''
    OR B IS NULL OR B = ''
    OR C IS NULL OR C = ''
    OR D IS NULL OR D = ''
    OR E IS NULL OR E = ''
    OR F IS NULL OR F = ''
    OR G IS NULL OR G = ''
    OR H IS NULL OR H = ''
    OR I IS NULL OR I = ''
    OR J IS NULL OR J = '';

1 个答案:

答案 0 :(得分:0)

您可以将运算符NOT应用于整个条件:

DELETE FROM BadData_Table   
WHERE NOT (
       A IS NULL OR A = ''
    OR B IS NULL OR B = ''
    OR C IS NULL OR C = ''
    OR D IS NULL OR D = ''
    OR E IS NULL OR E = ''
    OR F IS NULL OR F = ''
    OR G IS NULL OR G = ''
    OR H IS NULL OR H = ''
    OR I IS NULL OR I = ''
    OR J IS NULL OR J = ''
);

等效于:

DELETE FROM BadData_Table   
WHERE 
        A IS NOT NULL AND A <> ''
    AND B IS NOT NULL AND B <> ''
    AND C IS NOT NULL AND C <> ''
    AND D IS NOT NULL AND D <> ''
    AND E IS NOT NULL AND E <> ''
    AND F IS NOT NULL AND F <> ''
    AND G IS NOT NULL AND G <> ''
    AND H IS NOT NULL AND H <> ''
    AND I IS NOT NULL AND I <> ''
    AND J IS NOT NULL AND J <> ''
;