未从列表中返回的项目
我有一个 860 项长的项目列表。当我执行查询时: select * from tableA where item in (... items ...)
我得到 858 个项目。我想知道列表中的 2 项不在表 A 中。
NOT 返回表中不在列表中的所有项目,我想要列表中不在表中的所有项目。
I have a list of items that is 860 items long. When i execute the query: select * from tableA where item in (... items ...)
I get 858 items. I would like to know the 2 items in the list that are not in tableA.
NOT returns all of the items in the table that are not in the list, I want all the items in the list that are not in the table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我对这个问题的最初理解,我建议只添加关键字 NOT
但根据评论,上面不会返回你想要的内容。原始问题经过编辑以包含此新信息。
因此,您需要将 WHERE 子句中的数据转换为可查询的形式。这是一种方法,我创建一个名为“items”的附加表,并使用 INSERT 语句将每个项目放入此项目表中。由于我无权访问您的数据,因此我将使用整数作为项目并使用较少量的数据进行设置。
Based on my original understanding of the question, I suggested to just add the keyword NOT
But as per the comment the above will not return what you want. The original question was edited to include this new infomration.
So, you need to get your data from your WHERE clause into a form that is queryable. Here is one way to do it where I create an additional table named "items" and have INSERT statements to place each item into this items table. Since I do not have access to your data, I am going to use integers for the items and set it up with a smaller amount of data.
我建议您将列表转换为临时表(有大量的 udf 可供您使用,例如: http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/)
一旦你有了临时表
#List
,您可以执行以下操作;查看实际操作: https://data .stackexchange.com/stackoverflow/query/61259/items-not-returned-from-a-list
I would recommend that you convert your list into a temp table (there are a ton of udfs floating around that you can use ex: http://blog.sqlauthority.com/2007/05/06/sql-server-udf-function-to-convert-list-to-table/)
Once you have your temp table
#List
, you can do the following;See it in action: https://data.stackexchange.com/stackoverflow/query/61259/items-not-returned-from-a-list