我試圖用Laravel和查詢構建器來提高產品價格在1和最大產品價格之間的數量。在Laravel中的兩個值之間選擇查詢
我試圖與此查詢在phpMyAdmin,它返回一個結果:
SELECT product_id , count(user_id) , sum(monies)
FROM products, prices
WHERE monies
BETWEEN '20'
AND products.price
AND products.id = 101
GROUP BY (product_id);
但在PHP我coudn't指定上,我們必須搜索範圍:
$data = Product::join('prices', 'prices.product_id', '=', 'products.id')
->select(DB::raw('count(user_id) as nombre'),DB::raw('sum(monies) as sum'))
->where('prices.project_id', '=', '101')
->whereBetween('monies', array(1, 'products.price'))
->groupBy('prices.product_id')
->get();
但我總是得到一個空的結果,當我改變whereBetween('monies', array(1, 'products.price'))
與whereBetween('monies', array(1, 1000))
它返回一個結果。
如何使用whereBetween
?
該問題與whereBetween子句中與where'Between之間使用'products.price'相關的地方無關。 – 2014-11-03 16:46:29