Le reste de la formation est réservé aux inscrits.
S'inscrire gratuitementCREATE FUNCTION top_clients(n INT) RETURNS TABLE(nom TEXT, ca NUMERIC) AS $$ BEGIN RETURN QUERY SELECT c.nom, SUM(co.montant) FROM clients c JOIN commandes co ON c.id=co.client_id GROUP BY c.nom ORDER BY SUM(co.montant) DESC LIMIT n; END; $$ LANGUAGE plpgsql;