用于查找类似字段的SQL查询

时间:2021-07-30 15:46:31

In SQL, I have a table which have fields a_1,a_2,..., a_10. What kind of query says if I have rows s,t such that s.a_1=t.a_1 ,..., s.a_6=t.a_6 and for some j>6 we have s.a_i<>t.a_i?

在SQL中,我有一个表,其中包含字段a_1,a_2,...,a_10。什么样的查询说如果我有行s,t这样s.a_1 = t.a_1,...,s.a_6 = t.a_6而对于某些j> 6我们有s.a_i <> t.a_i?

1 个解决方案

#1


2  

Join table to itself on the condition you supplied. Like:

根据您提供的条件将表连接到自身。喜欢:

select
   a.ID 
from 
  table as a join table as b 
  on a.a_1 = b.a_1 and ... and a.a_j <> b.a_j

#1


2  

Join table to itself on the condition you supplied. Like:

根据您提供的条件将表连接到自身。喜欢:

select
   a.ID 
from 
  table as a join table as b 
  on a.a_1 = b.a_1 and ... and a.a_j <> b.a_j