query-e1539cc50dcbd8b3effbc425b3547076
ORDER inside a GROUP_CONCAT()?I’am trying to order individual episodes inside a concatenated result. Without the GROUP_CONCAT the episodes are ordered correctly, with they start at ?nr “100″. Is there a method to order the result inside the GROUP_CONCAT?
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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/>
SELECT (GROUP_CONCAT(?episode; SEPARATOR = " # ") AS ?episodelist) WHERE {
{
SELECT (CONCAT(?nr, " ", ?OT, "\n") AS ?episode) WHERE {
{
?qid p:P179 ?series;
wdt:P31 wd:Q21191270.
?series ps:P179 wd:Q728553;
pq:P1545 ?nr.
?qid rdfs:label ?OT.
FILTER((LANG(?OT)) = "en")
}
}
ORDER BY xsd:integer(?nr)
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?OT")
v5("?episode"):::projected
v6("?episodelist")
v1("?nr")
v3("?qid")
v4("?series")
c6(["wd:Q728553"]):::iri
c4(["wd:Q21191270"]):::iri
f0[["?OT = 'en'"]]
f0 --> v2
v3 --"p:P179"--> v4
v3 --"p:direct/P31"--> c4
v4 --"p:statement/P179"--> c6
v4 --"p:qualifier/P1545"--> v1
v3 --"rdfs:label"--> v2
bind1[/"concat(?nr,' ',?OT,'
')"/]
v1 --o bind1
v2 --o bind1
bind1 --as--o v5
bind3[/"?episode"/]
v5 --o bind3
bind3 --as--o v6