query-0b3f43f2e1bfd1e40b9668f414cabb99
]reply[19:51, 11 May 2022 (UTC)) talk (Игорь Темиров field separated by commas? With thanks spousesHow can I make it so that if there are two wives, they are displayed not in a separate line, but in the : By using the GROUP_CONCAT aggregation function for ?spouse and/or ?spouseLabel, and use GROUP BY for the other variables in the SELECT. To aggregate over a label, you also need to use the manual version of the label service:Игорь Темиров@
Use at
- https://query.wikidata.org/sparql
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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?p ?pLabel (GROUP_CONCAT(?spouse; separator=", ") AS ?spouses) (GROUP_CONCAT(?spouseLabel; separator=", ") AS ?spouseLabels) WHERE {
BIND(wd:Q30 AS ?country)
?country (p:P6/ps:P6) ?p.
?p wdt:P26 ?spouse.
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
?p rdfs:label ?pLabel.
?spouse rdfs:label ?spouseLabel.
}
}
GROUP BY ?p ?pLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v1("?country")
v2("?p"):::projected
v4("?pLabel"):::projected
v3("?spouse"):::projected
v5("?spouseLabel"):::projected
v7("?spouseLabels")
v6("?spouses")
a1((" "))
c5(["bd:serviceParam"]):::iri
c7(["#91;AUTO_LANGUAGE#93;,en"]):::literal
bind0[/"'wd:Q30'"/]
bind0 --as--o v1
v1 --"p:P6"--> a1
a1 --"p:statement/P6"--> v2
v2 --"p:direct/P26"--> v3
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c5 --"wikibase:language"--> c7
v2 --"rdfs:label"--> v4
v3 --"rdfs:label"--> v5
end
bind3[/"?spouse"/]
v3 --o bind3
bind3 --as--o v6
bind4[/"?spouseLabel"/]
v5 --o bind4
bind4 --as--o v7