Prueba asi:
Código sql:
Ver originalSELECT licencia
FROM (
SELECT tabla2.licencia,SUM(licencia) AS maximo
FROM (SELECT licencia,
DAY(tabla1.fechahora) AS dia,
MONTH(tabla1.fechahora) AS mes,
YEAR(tabla1.fechahora) AS año
FROM (SELECT licencia,cantidad,fechahora
FROM entrega
WHERE cantidad='5000') AS tabla1) AS tabla2
GROUP BY tabla2.licencia,tabla2.dia,tabla2.mes,tabla2.año
HAVING COUNT(*)>1) [tabla101]
WHERE maximo = (SELECT MAX(maximo) FROM tabla101)