mysql – laravel有:未找到列

我的以下代码是这样的:

$places = DivePlace::selectRaw("*,(st_distance_sphere( POINT(".$lon.",".$lat.") ,  point(lon, lat))/1000) as distance")
    ->havingRaw("distance < ".$radius)
    ->orderBy("distance")
    ->paginate(10);

没有“haveRaw”一切都很好.
添加后,出现以下错误:

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中 where与having的区别


下一篇:[转] “error LNK2019: 无法解析的外部符号”之分析