Laravel 如何从每个小组获得最便宜的产品

Laravel 如何从每个小组获得最便宜的产品,laravel,Laravel,如何使用laravel ORM执行以下操作 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; 我还没有测试过代码,但希望它能正常工作。请添加有关模型和关系的详细信息。包含列类型、种类和价

如何使用laravel ORM执行以下操作

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;

我还没有测试过代码,但希望它能正常工作。

请添加有关模型和关系的详细信息。包含列类型、种类和价格的水果表谢谢!成功了。我也要参加明普莱斯$加入->打开('fruits.price',x.price)。
$subQuery = "(select type, min(price) as minprice from fruits group by type) as x";
$query = DB::table('fruits')::selectRaw( "fruits.type,fruits.variety,x.minprice" );
$query->join( DB::raw($subQuery), function ($join) {
    $join->on ( 'fruits.type', '=', 'x.type' );
});
$data = $query->get();