Couchbase/N1QL-获取所有不存在的连接记录(内部连接的相反/相反)

Couchbase/N1QL-获取所有不存在的连接记录(内部连接的相反/相反),couchbase,n1ql,Couchbase,N1ql,查询以获取实际存在的接头记录,以及存在的所有制造商缺陷: select md.f_manufacturerId, md.f_defectId from productionlines as md inner join productionlines as m on m.type="manufacturer" and m.manufacturerId=md.f_manufacturerId inner join productionlines as d on d.type=

查询以获取实际存在的接头记录,以及存在的所有制造商缺陷:

select
      md.f_manufacturerId, md.f_defectId
  from productionlines as md
  inner join productionlines as m on m.type="manufacturer" and m.manufacturerId=md.f_manufacturerId
  inner join productionlines as d on d.type="defect" and d.defectId=md.f_defectId
  where md.type="manufacturerdefect"
  order by md.f_manufacturerId
我想要与此相反/相反的。。。 我想知道我们没有的制造商接头缺陷清单

数据结构

制造商:

{
  "name": "Ball Bearings"
  "id": "00a4260956d54e46932001d853df843c",
  "manufacturerId": 28,
  "type": "manufacturer"
}


{
  "name": "Wheel Rims"
  "id": "3ad4b5c6433d6e8b9c230fdd5dda8b33",
  "manufacturerId": 2,
  "type": "manufacturer"
}
缺陷:

{
  "name": "Bad Drill Bit"
  "id": "c348fd358d10023964e45d6590624a00",
  "defectId": 7,
  "type": "defect"
}


{
  "name": "Bad Shipping"
  "id": "33b8add5ddf032c9b8e6d3346c5b4da3",
  "defectId": 9,
  "type": "defect"
}
制造商缺陷:

{
  "id": "de426435bd10023964e45d6590624a00",
  "f_defectId": 7,
  "f_manufacturerId": 2,
  "type": "manufacturerdefect"
}

{
  "id": "de426435bd10023964e45d6590624a01",
  "f_defectId": 9,
  "f_manufacturerId": 2,
  "type": "manufacturerdefect"
}

{
  "id": "de426435bd10023964e45d6590624a02",
  "f_defectId": 7,
  "f_manufacturerId": 28,
  "type": "manufacturerdefect"
}

{
  "id": "de426435bd10023964e45d6590624a03",
  "f_defectId": 9,
  "f_manufacturerId": 28,
  "type": "manufacturerdefect"
}

因此,为了清楚起见,如果上述任何制造商缺陷不存在,我想知道所有缺失的制造商和缺陷id组合。

步骤1:查找所有组合

步骤2:排除所有现有的制造缺陷

(select
    m.manufacturerId as manufacturerId, d.defectId as defectId
from productionlines as d
inner join productionlines as m on m.type="manufacturer"
where d.type="defect"
order by m.manufacturerId)
EXCEPT
(select
    md.f_manufacturerId as manufacturerId, md.f_defectId as defectId
from productionlines as md
where md.type="manufacturerdefect")
order by manufacturerId

好的,为了得到目前所有的组合都有很多这样的组合,我可以运行以下查询:选择m.manufacturerId作为manufacturerId,选择d.defectId作为defectId从productionlines作为d内部连接productionlines作为m on m.type=manufacturer,其中d.type=缺陷订单由m.manufacturerId立即执行,如果我能从列表中筛选出现有的制造商缺陷。。。然后归还剩下的东西。。。