我试着用这个代码过滤b列中是否不存在a列的id。
query = db.session.query().select_from(Spare_Parts, Vendors, Replacement)\
.filter(Vendors.vendor_code == Spare_Parts.vendor_code,\
~ exists().where(Spare_Parts.spare_part_code == Replacement.spare_part_code))
我想从中查询数据 Spare_Parts
中不存在id的 Replacement
但我犯了这样的错误。
Select statement 'SELECT *
FROM spare_parts, replacement
WHERE spare_parts.spare_part_code = replacement.spare_part_code' returned no FROM clauses due to auto-correlation; specify correlate(<tables>) to control correlation manually.
那么什么是问题以及如何解决。
1条答案
按热度按时间i5desfxk1#
尝试像这样使用子查询
从下列备件中筛选备件代码:
not in
替换表``或者你可以用
not exists
```SELECT *
FROM spare_parts
WHERE not exists
(select 1
FROM replacement
where spare_parts.spare_parts_code = replacement.spare_parts_code)