我必须选择一些与给定坐标有一定距离的位置点。 提出查询
$locations = Locations::query()->columns(['id','distance' => '(1+2)'])
->order('distance')
->having('distance < 10')
->execute();
产生错误:
SELECT id, (1+2) AS distance FROM [Multiple\Base\Models\Locations] GROUP BY [distance < 10] ORDER BY distance (116)...
为什么我可以在 order 子句中使用 'distance' 别名,但不能在 having/where 中使用?
如何获取?
下面的查询有效,但我需要按距离对结果集进行排序并在 View 中使用距离...
$locations = Locations::query()->columns(['id'])
->having('(1+2) < 10')
->execute();
最佳答案
这是 MySQL 而非 Phalcon 强加的限制。尝试执行:
SELECT id, (1+2) AS distance FROM locations WHERE distance < 10;
从 mysql 命令行,您将收到相同的错误。
关于php - Phalcon:不能在 where/having 子句中使用别名列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32408122/