query-243da65aa9977e2c9f9db6c2f0839585

rq turtle/ttl

UNIONSGROUP_CONCAT()/GROUP BY

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?person ?personLabel
(GROUP_CONCAT(DISTINCT ?givenName; separator=", ") AS ?names)
(GROUP_CONCAT(DISTINCT ?occupation; separator=", ") AS ?occupations) {
  SELECT ?person ?personLabel ?givenName ?occupation {
    ?person wdt:P509 wd:Q175111.
    ?hasSitelink schema:about ?person; schema:isPartOf <https://de.wikipedia.org/>.
  #   ?person wdt:P31/wdt:P279* wd:Q5. # probably You don't need this, as only humans will be hanged
    OPTIONAL { ?person wdt:P735 ?givenNameItem. }
    OPTIONAL { ?person wdt:P106 ?occupationItem. }
    # ... more OPTIONAL patterns of this kind would go here ...
    SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en". ?person rdfs:label ?personLabel. ?givenNameItem rdfs:label ?givenName. ?occupationItem rdfs:label ?occupation. }
  }
} GROUP BY ?person ?personLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?givenName"):::projected v3("?givenNameItem") v2("?hasSitelink") v8("?names") v7("?occupation"):::projected v4("?occupationItem") v9("?occupations") v1("?person"):::projected v5("?personLabel"):::projected c5([https://de.wikipedia.org/]):::iri c2(["wd:Q175111"]):::iri c9(["bd:serviceParam"]):::iri c11(["de,en"]):::literal v1 --"wdt:P509"--> c2 v2 --"schema:about"--> v1 v2 --"schema:isPartOf"--> c5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P735".-> v3 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P106".-> v4 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 v1 --"rdfs:label"--> v5 v3 --"rdfs:label"--> v6 v4 --"rdfs:label"--> v7 end bind2[/"?givenName"/] v6 --o bind2 bind2 --as--o v8 bind3[/"?occupation"/] v7 --o bind3 bind3 --as--o v9