PREFIX ex: SELECT ?s ?c WHERE { ?s a ex:T. OX_LATERAL(?s) {SELECT (MAX(?o) AS ?c) WHERE { ?s ex:p ?o } GROUP BY ?s} }