My COUNT(*)
in the query below is selecting the count of the number of rows in the table users
rather than the number of rows where distance
is less than 50.
Please can you tell me why the query is selecting the number of rows in the table users
rather than the number of rows where the distance is less than 50?
Thanks in advanced.
SELECT COUNT(*), ( 6371 * ACOS( COS( RADIANS( 51.61050836267012 ) ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS( - 0.23701071739196777 ) ) + SIN( RADIANS( 51.61050836267012 ) ) * SIN( RADIANS( latitude ) ) ) )
AS distance
FROM `users`
AS `u`
HAVING distance <=50
HAVING
should be related to GROUP BY
expression. To restrict number of rows to a given criteria use WHERE distance <= 50
HAVING
适用于聚合值(例如具有特定条件的sum(列))在您的情况下应该使用WHERE
而不是HAVING
The having clause doesn't filter on rows like a where clause would for your count function. Try using a subquery instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.