我如何使用 Laravel 查询生成器 select 数据,其中最小多列位于一个范围之间?
How can I select data where minimum of multiple columns is between a range using Laravel Query Builder?
我想 select 使用 Laravel 查询生成器获取特定范围内最少 3 列的数据。
我当前的密码是
->whereBetween('price_one', [$min, $max])
->whereBetween('price_two', [$min, $max])
->whereBetween('price_three', [$min, $max])
此 selects 数据,其中所有价格都在 $min 和 $max 之间,但我想要 select 产品,其中最低价格在 $min 和 $max 之间。
如何重构我的代码来实现这一点?
将whereRaw
与LEAST()
一起使用:
whereRaw("LEAST(price_one, price_two, price_three) BETWEEN ? AND ?", [$min, $max])
我想 select 使用 Laravel 查询生成器获取特定范围内最少 3 列的数据。
我当前的密码是
->whereBetween('price_one', [$min, $max])
->whereBetween('price_two', [$min, $max])
->whereBetween('price_three', [$min, $max])
此 selects 数据,其中所有价格都在 $min 和 $max 之间,但我想要 select 产品,其中最低价格在 $min 和 $max 之间。
如何重构我的代码来实现这一点?
将whereRaw
与LEAST()
一起使用:
whereRaw("LEAST(price_one, price_two, price_three) BETWEEN ? AND ?", [$min, $max])