SELECT browser
,MIN(CAST(version AS DECIMAL(4,1))) minVersion
,MAX(CAST(version AS DECIMAL(4,1))) maxVersion
,MAX(c.stamp) lastVisit
,COUNT(DISTINCT c.id) visits
,SUM(a.firstAccess = c.id AND v.firstAgent = a.id) newVisits
FROM visitUser e
JOIN visitAccess c ON e.access = c.id
JOIN visitAgent a ON c.agent = a.id
JOIN visit v ON a.visit = v.id
WHERE c.stamp BETWEEN TIMESTAMP(#from,'00:00:00') AND TIMESTAMP(#to,'23:59:59')
GROUP BY browser ORDER BY visits DESC