python - 如何将多个条件传递给 python peewee 的 join 参数?

标签 python peewee

我想知道如何在 peewee 中执行以下 SQL 查询。

SELECT
    farmers.fruit_count,
    vendors.fruit_count,
FROM
    farmers
INNER JOIN
    vendors
ON
    farmers.location = vendors.location
AND
    farmers.alliance = vendors.alliance
AND
    farmers.fruit_count > 0

ON-AND-AND-... 在 peewee 中是否可行?关于 on 参数的文档并不多。我必须求助于 where() 吗?我假设查询如下所示,假设 on 参数采用与 where() 相同的形式:

Farmers.select(Farmers.fruit_count,
               Vendors.fruit_count)
       .join(Vendors,
             join_type=JOIN.INNER,
             on=(Farmers.location == Vendors.location,
                 Farmers.alliance == Vendors.alliance,
                 Farmers.fruit_count > 0)

最佳答案

只需使用&加入条件:

on=((Farmers.location == Vendors.location) &
    (Farmers.alliance == Vendors.alliance) &
    (Farmers.fruit_count > 0))

关于python - 如何将多个条件传递给 python peewee 的 join 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44209454/

相关文章:

python - Peewee 在运行时注册一个新模型

python - 如何删除 peewee 模型对象字段

python删除以 '\u...'开头的单词

python - 在 Raspberry 上使用 Python 进行传感器监控

python - 自定义字段 Django Rest Framework

peewee - peewee中的多个连接

mysql - 避免表中的列标题冲突加入 peewee

python - pee wee Meta 子类继承

python - 在 Python 的 GEKKO 中实现宏观经济模型

python - 从最后一个产生的对象而不是值中查找元素