query-4473b4da9666ab021399e5aebbc8fa91

rq turtle/ttl

Canadian actors who twice played a US president SELECT ?actor ?actorLabel (GROUP_CONCAT(?movieLabel; separator = "; ") AS ?movies) (GROUP_CONCAT(?presidentLabel; separator = "; ") AS ?presidents) WHERE { ?actor wdt:P31 wd:Q5; wdt:P27 wd:Q16; p:P106/ps:P106 wd:Q33999. ?movie p:P161 [ ps:P161 ?actor; pq:P453 ?president ]. ?president p:P39/ps:P39 wd:Q11696. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?actor rdfs:label ?actorLabel. ?movie rdfs:label ?movieLabel. ?president rdfs:label ?presidentLabel. } } GROUP BY ?actor ?actorLabel HAVING(COUNT(DISTINCT ?movie) = 2)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Canadian actors who twice played a US president
SELECT
?actor ?actorLabel
(GROUP_CONCAT(?movieLabel; separator = "; ") AS ?movies)
(GROUP_CONCAT(?presidentLabel; separator = "; ") AS ?presidents)
WHERE {
  ?actor wdt:P31 wd:Q5;
         wdt:P27 wd:Q16;
         p:P106/ps:P106 wd:Q33999.
  ?movie p:P161 [
    ps:P161 ?actor;
    pq:P453 ?president
  ].
  ?president p:P39/ps:P39 wd:Q11696.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    ?actor rdfs:label ?actorLabel.
    ?movie rdfs:label ?movieLabel.
    ?president rdfs:label ?presidentLabel.
  }
}
GROUP BY ?actor ?actorLabel
HAVING(COUNT(DISTINCT ?movie) = 2)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?_anon_42b5416610844a34809f33a099ae9de176078") v1("?actor"):::projected v4("?actorLabel"):::projected v3("?movie") v5("?movieLabel"):::projected v8("?movies") v2("?president") v6("?presidentLabel"):::projected v9("?presidents") a2((" ")) a3((" ")) a4((" ")) a1((" ")) c5(["wd:Q16"]):::iri c16(["bd:serviceParam"]):::iri c3(["wd:Q5"]):::iri c18(["#91;AUTO_LANGUAGE#93;,en"]):::literal c8(["wd:Q33999"]):::iri c14(["wd:Q11696"]):::iri f0[[" = '2^^xsd:integer'"]] f0 --> a1 v1 --"p:direct/P31"--> c3 v1 --"p:direct/P27"--> c5 v1 --"p:P106"--> a2 a2 --"p:statement/P106"--> c8 a3 --"p:statement/P161"--> v1 a3 --"p:qualifier/P453"--> v2 v3 --"p:P161"--> a3 v2 --"p:P39"--> a4 a4 --"p:statement/P39"--> c14 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c16 --"wikibase:language"--> c18 v1 --"rdfs:label"--> v4 v3 --"rdfs:label"--> v5 v2 --"rdfs:label"--> v6 end bind4[/"count(?movie)"/] v3 --o bind4 bind4 --as--o v7 bind5[/"?movieLabel"/] v5 --o bind5 bind5 --as--o v8 bind6[/"?presidentLabel"/] v6 --o bind6 bind6 --as--o v9