The value of the alias when the sentence for the same request

I want to get the result where distance> = distance_filter, which we retrieve in the same request

SELECT SQL_CALC_FOUND_ROWS null as row, distance_filter, j.lat, j.long, ROUND((((acos(sin((28.53551600*pi()/180)) * sin((j.lat*pi()/180)) + cos((28.53551600*pi()/180)) * cos((j.lat*pi()/180)) * cos(((77.39102600 - j.long) * pi()/180))))*180/pi())*60*1.1515*1.609344 )) as distance, j.job_id, j.brand, j.location, j.model, j.creation_time
FROM `mb_job` as `j`
JOIN `mb_job_issue` as `ji` ON `j`.`job_id`=`ji`.`job_id`
WHERE `j`.`creation_time` >= '2017-05-18 09:39:43'
AND `j`.`status` = '1'
AND `j`.`job_id` NOT IN('')
GROUP BY `j`.`job_id`
HAVING `distance` <= 'DISTANCE_FILTER'
ORDER BY `j`.`job_id` DESC
 LIMIT 10

Thanks in advance for any recommendations.

+4
source share
2 answers

You just need to put the sentence in one quote. This query works fine on my end

SELECT SQL_CALC_FOUND_ROWS null as row, distance_filter, j.lat, j.long, ROUND((((acos(sin((28.53551600*pi()/180)) * sin((j.lat*pi()/180)) + cos((28.53551600*pi()/180)) * cos((j.lat*pi()/180)) * cos(((77.39102600 - j.long) * pi()/180))))*180/pi())*60*1.1515*1.609344 )) as distance, j.job_id, j.brand, j.location, j.model, j.creation_time
FROM `mb_job` as `j`
JOIN `mb_job_issue` as `ji` ON `j`.`job_id`=`ji`.`job_id`
WHERE `j`.`creation_time` >= '2017-05-18 09:39:43'
AND `j`.`status` = '1'
AND `j`.`job_id` NOT IN('')
GROUP BY `j`.`job_id`
HAVING 'distance <= distance_filter'
ORDER BY `j`.`job_id` DESC
 LIMIT 10

Hope this helps you

+2
source

You will need to use the whole calculation, for example

WHERE ROUND((((acos(sin((28.53551600*pi()/180)) * sin((j.lat*pi()/180)) + cos((28.53551600*pi()/180)) * cos((j.lat*pi()/180)) * cos(((77.39102600 - j.long) * pi()/180))))*180/pi())*60*1.1515*1.609344 )) >= distance filter

Or you can transfer this to the HAVING clause: HAVING distance >= distance_filter

+1
source

Source: https://habr.com/ru/post/1677530/


All Articles