如何 select 来自一个 table 的条目,其中某个字段在另一个 table 中不存在

How to select entries from one table where a certain field is not existing in the other table

如何从一个 table 中 select peewee ORM 中的条目,其中某个字段不在另一个 table 中?

例如 如何计算 tblemployees 中而不是 tblcards 中的员工?

select count(*) from tblEmployees 
   where name not in 
   (select employname from tblCards);

注意:“name”和“employname”这两个字段都不是各自的 primary/foreign 键)。

您应该提供您的模型定义。但是你有没有尝试过类似的东西:

Employee.select().where(Employee.name.not_in(Card.select(Card.employname))).count()