The first two queries work fine, the 3rd one runs but brings back nothing when there should be results. How can I get the 3rd one to bring back results. It seems to me the GROUP BY
and HAVING
are not working together.
The 2nd query returns 32 Active Status and 7 Pending Status, so the 3rd query should return a summary of the 2nd query, but it is not.
SELECT COUNT(DISTINCT MLSNumber) AS TOTAL, `Status`
FROM Residential
WHERE PropertyType='Single Family' AND Status IN ("Active", "Pending")
GROUP BY `Status`;
SELECT MLSNumber, `Status`,
( 3959 * acos( cos( radians(21.380936) ) * cos( radians( Latitude ) )
* cos( radians( Longitude ) - radians(-157.757438) ) + sin( radians(21.380936) )
* sin(radians(Latitude)) ) ) AS distance
FROM Residential
WHERE PropertyType='Single Family' AND Status IN ("Active", "Pending")
HAVING distance < 2;
SELECT COUNT(DISTINCT MLSNumber) AS TOTAL, `Status`,
( 3959 * acos( cos( radians(21.380936) ) * cos( radians( Latitude ) )
* cos( radians( Longitude ) - radians(-157.757438) ) + sin( radians(21.380936) )
* sin(radians(Latitude)) ) ) AS distance
FROM Residential
WHERE PropertyType='Single Family' AND Status IN ("Active", "Pending")
GROUP BY `Status`
HAVING distance < 2;