我试图抓住里程数在$range
和$interval
之内的车辆。目前,有大量between ? and ?
条款正在大大减慢查询速度。有没有更好的方法来实现这一目标?我认为模运算可能会起作用,尽管$range
会使其变得更加困难。
$interval = 15000;
$range = 5000;
$max = 3000000;
for ($i = $interval; $i < $max; $i += $interval)
{
$between = [
$i - $range,
$i + $range,
];
// generates "WHERE mileage BETWEEN ? AND ? OR mileage BETWEEN ? AND ? ..."
$query->orWhereBetween('mileage', $between);
}
答案 0 :(得分:3)
select .. where (mileage>=15000) and ((mileage-10000) mod 15000)<=10000