实体A
有一个字段name
实体B
有一个字段city
实体C
包含字段lat
和lon
实体A
与名为B
的实体bees
有一对多的关联
实体B
与名为C
cees
有多对一关联
现在我要选择距离Y点X公里范围内的所有A
个实体。
X = 20
Y = lat:52.25,lon:4.53
DQL:
SELECT a, ( 6371 * acos( cos( radians(52.25) ) * cos( radians( c.lat ) ) * cos( radians( c.lon ) - radians(4.53) ) + sin( radians(52.25) ) * sin( radians( c.lat ) ) ) ) AS distance FROM A a LEFT JOIN a.bees b LEFT JOIN b.cees c WHERE distance < 20
当我执行这个DQL时,我得到:
An exception occurred while executing 'SELECT m0_.name AS name0, m0_.id AS id11, (6371 * ACOS(COS(RADIANS(52.25)) * COS(RADIANS(p1_.lat)) * COS(RADIANS(p1_.lon) - RADIANS(4.53)) + SIN(RADIANS(52.25)) * SIN(RADIANS(p1_.lat)))) AS sclr12, FROM table_a m0_ LEFT JOIN table_b m2_ ON m0_.id = m2_.a_id LEFT JOIN table_c p1_ ON m2_.b_id = p1_.id WHERE sclr12 < 20':
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sclr12' in 'where clause'`
我在这里做错了什么? 非常感谢任何帮助!
约拉姆