我想知道如何在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参数的文档很少。我必须诉诸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))

07-24 09:27