INSERT INTO daily_agg (day, site_id, path, pageviews, uniques)
SELECT DATE(ts), site_id, path,
       COUNT(*), COUNT(DISTINCT visitor_hash)
FROM events
WHERE ts >= CURDATE() - INTERVAL 2 DAY
GROUP BY DATE(ts), site_id, path
ON DUPLICATE KEY UPDATE
  pageviews = VALUES(pageviews),
  uniques = VALUES(uniques);