Sql 当我们按列(C1)分组时,选择列(C2)中缺少特定值(V1)的特定列(C1)
我有一个postgres表,如下所示:Sql 当我们按列(C1)分组时,选择列(C2)中缺少特定值(V1)的特定列(C1),sql,postgresql,Sql,Postgresql,我有一个postgres表,如下所示: C1 C2 ------------------------------------- apple No Thorns apple No Thorns orange Thorns apple No Thorns pineapple
C1 C2
-------------------------------------
apple No Thorns
apple No Thorns
orange Thorns
apple No Thorns
pineapple No Thorns
pineapple Thorns
guava No Thorns
guava Thorns
现在,我想要在一次查询中从未在C2中找到刺的那些水果的名称C1。
如果这件事很琐碎,我会提前道歉
以上问题的答案是苹果公司我将通过以下方式使用该小组: 我会试试看
Select distinct c1 from table1
Where not exists (
Select 1 from table1 t2 where table1.c1 = t2.c1 and t2.c2 = 'Thorns')
Select distinct c1 from table1
Where not exists (
Select 1 from table1 t2 where table1.c1 = t2.c1 and t2.c2 = 'Thorns')