[英]Compare price range value to two columns to product table, product regular price and product sale price
I have two columns in table name as product regular price and product sale price.我在表名中有两列,分别是产品正常价格和产品销售价格。 I have to search min price products against a price range given by the user.
我必须根据用户给出的价格范围搜索最低价格产品。 It is easy to search min price from a single column but from both columns, it seems very difficult.
从单列中搜索最低价格很容易,但从两列中搜索似乎非常困难。
$products = $products->whereBetween(['ecommerce_sku.regular_price','ecommerce_sku.sale_price'], [$minPrice, $maxPrice]);
You can separate regular price and sales price.您可以将正常价格和销售价格分开。
$products = $products
->whereBetween('ecommerce_sku.sale_price', [$minPrice, $maxPrice])
->whereBetween('ecommerce_sku.regular_price', [$minPrice, $maxPrice]);
Raw query:原始查询:
$string = '(ecommerce_sku.sale_price between "'.$minPrice.'" and "'.$maxPrice.'") AND (ecommerce_sku.regular_price between "'.$minPrice.'" and "'.$maxPrice.'")'
$products = $products->whereRaw($string);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.