Among the information that is not listed is how the campground tables and markers are related. We will need this information to know how to connect to tables.
, HAVING GROUP BY ( WHERE GROUP BY). , , .
, - :
SELECT id (expression) as distance FROM markers
WHERE distance < 25 AND
campground_id IN (SELECT id FROM campgrounds WHERE type = 'private' AND wifi = 1)
EDIT: , .
ALIASes WHERE. , , , HAVING, HAVING WHERE. GROUP BY:
SELECT campgroundid, name, private, wifi,
( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians(-122) ) +
sin( radians(37) ) * sin( radians( lat ) ) ) )
AS distance
FROM campground
GROUP BY campgroundid
HAVING distance < 25 AND type='private' AND wifi = 1
ORDER BY distance LIMIT 0 , 20;
, campgroundid ( id).