Reputation: 103
I am having this problem in a complex query. This is the simplificated version:
SELECT sin(3.14) as s from my_table where s < 1
Error: #1054 - Unknown column 's' in 'where clause'
Upvotes: 2
Views: 650
Reputation: 1404
HAVING
will SAVE You
SELECT *,(((acos(sin((".$lat."*pi()/180)) *sin((latitud*pi()/180))
+cos((".$lat."*pi()/180))
* cos((latitud*pi()/180))
* cos(((".$lng."- longitud)*pi()/180))))*180/pi())
*60*1.1515*1.609344) as distance
FROM pois_data,pois_cat
WHERE pois_data.idtipo=pois_cat.id AND latitud IS NOT NULL
HAVING distance <1
Upvotes: 4
Reputation: 109567
Create a VIEW on that table, with that expression as column.
CREATE VIEW vw
SELECT sin(3.14) AS s FROM my_table;
SELECT * FROM vw WHERE s < 1;
Or create a virtual column in the table itself.
CREATE TABLE my_table (
...,
s VIRTUAL FLOAT AS (sin(3.14))
);
Upvotes: 1