query: SELECT (wd:Q3464665 as ?item) ?statcount WHERE { SELECT (COUNT(DISTINCT ?item) as ?statcount) WHERE { ?item wdt:P31 wd:Q3464665 ; p:P179 ?st ; wdt:P1113 ?epnb . { SELECT ?item (COUNT(DISTINCT ?ep ) as ?count) WHERE { ?item wdt:P31 wd:Q3464665 ; wdt:P527 ?ep . ?ep wdt:P31 wd:Q21191270 } GROUP BY ?item } FILTER (?count >= ?epnb) } }