Php Phalcon:无法在where/having子句中使用别名列
我必须选择一些与给定坐标有距离的位置点。 提出的查询Php Phalcon:无法在where/having子句中使用别名列,php,mysql,where-clause,phalcon,calculated-columns,Php,Mysql,Where Clause,Phalcon,Calculated Columns,我必须选择一些与给定坐标有距离的位置点。 提出的查询 $locations = Locations::query()->columns(['id','distance' => '(1+2)']) ->order('distance') ->having('distance < 10') ->execute(); $locations=locations::quer
$locations = Locations::query()->columns(['id','distance' => '(1+2)'])
->order('distance')
->having('distance < 10')
->execute();
$locations=locations::query()->列(['id','distance'=>'(1+2)])
->顺序(“距离”)
->有('距离<10')
->执行();
产生错误:
SELECT id, (1+2) AS distance FROM [Multiple\Base\Models\Locations] GROUP BY [distance < 10] ORDER BY distance (116)...
选择id,(1+2)作为与[multi\Base\Models\Locations]的距离按[distance<10]分组按距离排序(116)。。。
为什么我可以在order子句中使用'distance'别名,但不能在have/where中使用
如何得到它
下面的查询有效,但我需要按距离对结果集排序,并在视图中使用距离
$locations = Locations::query()->columns(['id'])
->having('(1+2) < 10')
->execute();
$locations=locations::query()->列(['id'])
->有('(1+2)<10')
->执行();
这是MySQL而不是Phalcon施加的限制。尝试执行:
SELECT id, (1+2) AS distance FROM locations WHERE distance < 10;
选择id,(1+2)作为距离<10的位置的距离;
从mysql命令行,您将收到相同的错误