I have this query that calculates the distance between 2 points given certain coordinates.
The query runs well, the problem is the WHERE of the query, this is the error:
Error Code: 1054. Unknown column 'dist' in 'where clause'
If I run the query without the WHRE if it throws me the result I want the problem is the WHERE.
What am I doing wrong
SELECT p.*,
(
6371 *
(2 *
atan2(
sqrt(
(
sin(
radians(
(p.Punto_Latitude__c - 19.4326077) / 2
)
)
*
sin(
radians(
(p.Punto_Latitude__c - 19.4326077) / 2
)
)
)
+
(
cos(
radians(19.4326077)
)
*
cos(
radians(p.Punto_Latitude__c)
)
)
*
(
sin(
radians(
(p.Punto_Longitude__c - (-99.015725)) / 2
)
)
*
sin(
radians(
(p.Punto_Longitude__c - (-99.015725)) / 2
)
)
)
),
sqrt(1 -
(
sin(
radians(
(p.Punto_Latitude__c - 19.4326077) / 2
)
)
*
sin(
radians(
(p.Punto_Latitude__c - 19.4326077) / 2
)
)
)
+
(
cos(
radians(19.4326077)
)
*
cos(
radians(p.Punto_Latitude__c)
)
)
*
(
sin(
radians(
(p.Punto_Longitude__c - (-99.015725)) / 2
)
)
*
sin(
radians(
(p.Punto_Longitude__c - (-99.015725)) / 2
)
)
)
)
)
)
) as dist
FROM places as p
WHERE dist > 100