如何在 Laravel 中搜索 MIN 和 MAX

How to Search Between MIN and MAX in Laravel

我知道在 MySQL 中查询看起来像这样...

SELECT id 
    FROM listings 
    WHERE id  IN (
      SELECT id
      FROM listings
      WHERE price between 200 and 500
    );

在 Laravel 查询中我试过...

Listing::select('listings.*')
    ->whereBetween('price', [200, 500])
    ->groupBy('listings.id')
    ->orderBy('listings.id', 'desc')
    ->paginate(1000);

它只显示了一个结果。我哪里做错了吗?感谢您的帮助!

Listing::select('listings.*')
                 ->whereRaw("(listings.price <= ? AND listings.price >= ?) ", [500, 200])
                 ->groupBy('listings.id')
                 ->orderBy('listings.id', 'desc')
                 ->paginate(1000);

尝试

Listing:: where(price, '>=', 200 )
                 ->where(price, '<=', 500 )
                 ->groupBy('id')
                 ->orderBy('id', 'desc')
                 ->paginate(1000);