我必须选择一些位置点与给定坐标的距离。呈现查询
$locations = Locations::query()->columns(['id','distance' => '(1+2)'])
->order('distance')
->having('distance < 10')
->execute();
产生错误:
SELECT id, (1+2) AS distance FROM [MultipleBaseModelsLocations] GROUP BY [distance < 10] ORDER BY distance (116)...
为什么我可以在order子句中使用'distance'别名,而不能在having/where中使用?
如何得到它?
下面的查询工作,但我需要排序结果集的距离和使用距离的视图…
$locations = Locations::query()->columns(['id'])
->having('(1+2) < 10')
->execute();
这是MySQL强加的限制,而不是Phalcon。尝试执行:
SELECT id, (1+2) AS distance FROM locations WHERE distance < 10;