我知道在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);
它只显示一个结果。我在哪里出错了?谢谢您的帮助!
答案 0 :(得分:4)
尝试
Listing:: where(price, '>=', 200 )
->where(price, '<=', 500 )
->groupBy('id')
->orderBy('id', 'desc')
->paginate(1000);
答案 1 :(得分:2)
Listing::select('listings.*')
->whereRaw("(listings.price <= ? AND listings.price >= ?) ", [500, 200])
->groupBy('listings.id')
->orderBy('listings.id', 'desc')
->paginate(1000);