I'm trying to return a list of map items from my DB grouping the items ONLY if the group count is greater than 4 otherwise I don't want the items to be grouped.
My project is built to return all entries within a set area and I'll be using grouping to break up that area into a grid. If each cell in the grid has too many results then I will show a group marker with the group count instead of a single entry marker.
My current query works to determine if there are grouped items by the COUNT(*)
SELECT *, COUNT(*) as groupCount, floor(longitude/0.0007) AS groupLong, floor(latitude/0.0007) AS groupLat
FROM items
WHERE longitude>=151.1
AND longitude<=151.2
AND latitude>=-33.9
AND latitude<=-33.8
GROUP BY floor(longitude/0.0007), floor(latitude/0.0007)
What I would like to do is only group the items if the group count > 4 and items in a group <=4 will be returned as ungrouped items.
I know that I can use HAVING COUNT(*)>4
to only return the groups of 5 and over but what can I do to return the ungrouped items that would be in the groups of 4 and under?
I would be happy to do two queries to get the results but if there was a way of doing it in one then that would be great!