我有下表
|ID | NodeID |
|---|--------|
|1 | N001 |
|2 | N006 |
|3 | N0010 |
|4 | N0015 |
|5 | N0016 |
以下CSV字符串
'N001','N002','N003','N004','N005','N006','N007'
如何找到 IN CSV字符串并且 NOT IN 表格中的NodeID?
答案 0 :(得分:1)
根据您的环境和数据大小,有多种选择。这是我最常见的两个......
我喜欢的方式......
将CSV值插入表中,然后使用SQL ...
完成所有工作INSERT INTO myTempTable (itemValue) ......
SELECT * FROM myTempTable WHERE NOT EXISTS (SELECT * FROM dataTable WHERE NodeID = itemValue)
-- Or...
SELECT * FROM myTempTable LEFT JOIN dataTable ON NodeID = itemValue WHERE NodeID IS NULL
另一个选项可以避开临时表,但需要客户端处理......
第2步可以简单地完成......
SELECT * FROM dataTable WHERE NodeID IN (yourCSV) ORDER BY NodeID