Ho provato a fare una cosa del genere:

Codice PHP:
SELECT SUM(quantita) as totale FROM prodotti WHERE quantita=(SELECT quantitamax(quantita) AS maggiore
FROM prodotti WHERE data_aquisto
<='$al' AND data_aquisto>='$dal'group by id_cliente 
ma mi risponde

codice:
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Mi sa che ho superato il limite dell'impossibile del php e l'ho sparata grossa eh!!