我的以下代码是这样的:
$places = DivePlace::selectRaw("*,(st_distance_sphere( POINT(".$lon.",".$lat.") , point(lon, lat))/1000) as distance")
->havingRaw("distance < ".$radius)
->orderBy("distance")
->paginate(10);
没有“havingRaw”一切都很好。 添加后出现如下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from
dive_places
having distance < 300)
有什么解决办法吗?
最佳答案
->where(DB::raw("(ST_Distance_Sphere(POINT(".$lon.",".$lat."), POINT(lon,lat))/1000)"), '<', 200)
而不是 ->havingRaw("(st_distance_sphere( POINT(?, ?) , point(lon, lat))/1000) < ?", [$lon, $lat, $radius])
关于mysql - Laravel 有 : Column not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33982661/