【发布时间】:2015-11-25 03:41:53
【问题描述】:
我有一个类似于Translate SQLite query, with subquery, into Peewee statement 和Can peewee nest SELECT queries such that the outer query selects on an aggregate of the inner query? 的问题。
我试图生成的结果是:给定一个包含(type, variety, price) 行的fruit 表,找出每种水果中最便宜的品种。 http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/ 描述了几个有效的解决方案:
select f.type, f.variety, f.price
from (
select type, min(price) as minprice
from fruits group by type
) as x inner join fruits as f on f.type = x.type and f.price = x.minprice;
或者:
select type, variety, price
from fruits
where price = (select min(price) from fruits as f where f.type = fruits.type);
我如何对其中一个或两个进行 Peewee-ify?
【问题讨论】: