Question : Mysql count not working on "having" sql query

Hi! I'm building a restaurant directory and have hit a brick wall with a minor inconvenience.

Please go to www.menumap.ca and change your city to Ottawa Ontario, then go here:
http://www.menumap.ca/proximity/K2J4C4/American/

You will see that based on a 20km radius from the postal code, there are less results available than the counter suggests next to the cuisine name.

All the numbers are the total number of restaurants in each cuisine, it does show the proper cuisines (no empty links) but the count() isn't working.

Here is the query, it works fine when no proximity query is taking place.

SELECT DISTINCT(cuisine),(6731 * acos(cos(radians('45.2927679')) * cos(radians(latitude)) * cos(radians(longitude) - radians('-75.7308939')) + sin(radians('45.2927679')) * sin(radians(latitude)))) AS distance,count(cuisine) as sum FROM restaurants where (legal_name like '%%' OR description like '%%') group by cuisine HAVING distance < '20'

Answer : Mysql count not working on "having" sql query

SELECT cuisine, count(cuisine) as sum
FROM
(
SELECT cuisine, (6731 * acos(cos(radians('45.2927679')) * cos(radians(latitude)) * cos(radians(longitude) - radians('-75.7308939')) + sin(radians('45.2927679')) * sin(radians(latitude)))) AS distance
FROM restaurants
where (legal_name like '%%' OR description like '%%')
) SQ
WHERE distance < 20
group by cuisine
Random Solutions  
 
programming4us programming4us