我下面的代码是这样的:
$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]:未找到列:1054中的未知列“distance”
'having子句'(SQL:select count(*)as aggregate from
dive_places
距离有什么解决办法吗?
最佳答案
->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具有:找不到列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33982661/