I have a query which returns map markers within a radius (in miles) of a given position (lat/lng). My query works when reading the data, but I am wanting to set up pagination so need to count the records first to determine how many pages of data I will have.

My query is :

```
SET @LAT := 53.068464;
SET @LNG := -4.076113;
SET @Miles := 10;

SELECT (3959 * acos( cos( radians(@LAT) ) * cos( radians( M.Lat ) ) * cos( 
radians( M.Lng ) - radians(@LNG) ) + sin( radians(@LAT) ) * sin( radians( 
M.Lat ) ) ) ) AS distance, M.MarkerId, M.Title 
FROM Markers AS M 
HAVING distance < @Miles
ORDER BY M.DateStamp desc, Distance 

```

I have tried

```
SELECT COUNT(MarkerId) 
FROM Markers
HAVING (3959 * acos( cos( radians(@LAT) ) * cos( radians( Lat ) ) * cos( 
radians( Lng ) - radians(@LNG) ) + sin( radians(@LAT) ) * sin( radians( Lat ) 
) ) ) < @Miles

```

but it fails trying to reference the Lat and Lng fields from the Markers table.