我有这种结构的桌子。我试图找到单词中没有出现的所有唯一ID。如何在MS SQL Server中实现这一目标。
id word
1 hello
2 friends
2 world
3 cat
3 dog
2 country
1 phone
4 eyes
Run Code Online (Sandbox Code Playgroud)
我有一个词表
**List**
phone
eyes
hair
body
Run Code Online (Sandbox Code Playgroud)
预期产量
除了列表中的单词,我还需要所有唯一的ID。在这种情况下,
2
3
Run Code Online (Sandbox Code Playgroud)
I&4不在输出中,因为它们的单词出现在列表中
我尝试了以下代码
Select count(distinct ID)
from Table1
where word not in ('phone','eyes','hair','body')
Run Code Online (Sandbox Code Playgroud)
我也尝试了不存在也不起作用