在单个SQLITE

时间:2017-08-15 08:19:50

标签: sql sqlite csv

我将4个CSV文件导入SQLITE(mastersuppress, ddsummary, rm5, excludelist)。所有文件都包含1列(AccountNumber)。

我设法找到3个文件之间的重复帐号,并使用以下代码将结果保存在名为Output的新CSV文件中:

select mastersuppress.Account
from mastersuppress
inner join ddsummary
on mastersuppress.Account=ddsummary.Account
union all
select rm5.Account
from rm5
inner join ddsummary
on rm5.Account=ddsummary.Account

然后我设法使用第二个代码从Output文件中删除excludelist文件中的帐号以及帐号#:

delete   from Output
where    AccountNumber in
         (
         select  min(AccountNumber)
         from    excludelist
         group by
                 AccountNumber
         );

Select * FROM Output;   

如何将这2个代码编译成1个代码而无需在进程之间创建输出文件。所以代码看起来像这样

Delete   from ***FirstCodeResult***
    where    AccountNumber in
             (
             select  min(AccountNumber)
             from    excludelist
             group by
                     AccountNumber
             );

   //Display the result

1 个答案:

答案 0 :(得分:0)

我会使用except

来表达这一点
select m.Account
from mastersuppress m inner join
     ddsummary ds
     on m.Account = ds.Account
union 
select rm5.Account
from rm5 inner join 
     ddsummary ds
     on rm5.Account = ds.Account
except
select el.AccountNumber
from excludelist el;

exceptunion删除重复项。