query-d6ecad24f08c4142552425f966dc5e5c

rq turtle/ttl

Transpose multiple property statement values into columnsUse case here is an item with up to three P921 statements. I'd like a single row for the item, with the three P921 values displayed in three columns. I'm clearly some way from my target. This fails in an accessible sort of a way if I try to show two main subject columns:

Use at

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 ?ms1 ?ms1Label ?ms2 ?ms2Label WHERE 
{
  VALUES ?item {
    wd:Q99536927   # 3 P921s
    wd:Q99689936   # 2 P921s
    wd:Q99927619   # 1 P921
    wd:Q100144327  # 0 P921s
    }
  optional {?item wdt:P921 ?ms1 .
    optional {?item wdt:P921 ?ms2 . filter(str(?ms1) > str(?ms2) )
              } 
           }       
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en".}
  } order by ?item

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?item"):::projected v2("?ms1"):::projected v3("?ms2"):::projected c3(["bd:serviceParam"]):::iri c5(["en"]):::literal bind0[/VALUES ?item/] bind0-->v2 bind00(["wd:Q99536927"]) bind00 --> bind0 bind01(["wd:Q99689936"]) bind01 --> bind0 bind02(["wd:Q99927619"]) bind02 --> bind0 bind03(["wd:Q100144327"]) bind03 --> bind0 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P921".-> v2 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P921".-> v3 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c5 end