query-5f3eb13bb5a7e205ce5d72bcba5a797e
Grouping result by entity, not by propertyHi everyone, I'm dealing with the following query which gathers every painting with one or more depict properties. But when a painting has more than one depict, the results appear with one line by depict. My query: } } ."[AUTO_LANGUAGE],fr,en" language:wikibase serviceParam:bd { label:wikibase SERVICE .?depict P180:wdt ?item .?image P18:wdt ?item .Q4502142:wd *P279:wdt/P31:wdt ?item { WHERE ?depict ?image ?itemLabel ?item SELECTWhat I get : wd:Q235113 commons:Andrey Rublev - Архангел Михаил. Из Деисусного чина ("Звенигородский") - Google Art Project.jpg Saint Michel archange wd:Q18683117 wd:Q45581 commons:Andrey Rublev - Архангел Михаил. Из Деисусного чина ("Звенигородский") - Google Art Project.jpg Saint Michel archange wd:Q18683117 depict image itemLabel item Légende What I would like : wd:Q235113, wd:Q45581 commons:Andrey Rublev - Архангел Михаил. Из Деисусного чина ("Звенигородский") - Google Art Project.jpg Saint Michel archange wd:Q18683117 depicts image itemLabel item Légende 15:23, 28 February 2018 (UTC)) talk (GordibachIs there any way to get this kind of result? And other question: is there a way to query by the same way the paintings without depict, meaning make depicts optionnal? Thanks! Try this. However, I had to limit the number of results.
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 bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?image (GROUP_CONCAT(distinct ?depict ;separator=", ") as ?depecited) WHERE {
?item wdt:P31/wdt:P279* wd:Q4502142;
wdt:P18 ?image;
wdt:P180 ?depict.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en". }
}
GROUP BY ?item ?itemLabel ?image
LIMIT 100