query-89b5a1e281ae8b62c57005fc357c622c

rq turtle/ttl

TV series episodes list by production code & series ordinal (not season) SELECT ?show ?showLabel ?seriesLabel ?seriesOrdinal ?proCode ?seasonLabel WHERE { values ?series {wd:Q18844732} #series is Supergirl ?show wdt:P31 wd:Q21191270. #show is a television series episode ?show p:P179 ?statement. #show has a P179 claim OPTIONAL {?statement pq:P1545 ?seriesOrdinal.} #show might have a series ordinal ?statement ps:P179 ?series. #show is part of the series OPTIONAL {?show wdt:P2364 ?proCode.} #show might have a production code OPTIONAL {?show wdt:P4908 ?season.} #show might have multiple seasons SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY (!bound(?proCode)) ?proCode (!bound(?seriesOrdinal)) ?seriesOrdinal

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#TV series episodes list by production code & series ordinal (not season)
SELECT ?show ?showLabel ?seriesLabel ?seriesOrdinal ?proCode ?seasonLabel WHERE {
  values ?series {wd:Q18844732}        #series is Supergirl 
  ?show wdt:P31 wd:Q21191270.          #show is a television series episode
  ?show p:P179 ?statement.             #show has a P179 claim
  OPTIONAL {?statement pq:P1545 ?seriesOrdinal.} #show might have a series ordinal
  ?statement ps:P179 ?series.          #show is part of the series
  OPTIONAL {?show wdt:P2364 ?proCode.} #show might have a production code
  OPTIONAL {?show wdt:P4908 ?season.}  #show might have multiple seasons
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY (!bound(?proCode)) ?proCode (!bound(?seriesOrdinal)) ?seriesOrdinal

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?proCode"):::projected v6("?season") v3("?series") v2("?seriesOrdinal"):::projected v4("?show"):::projected v5("?statement") c9(["bd:serviceParam"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal c2(["wd:Q21191270"]):::iri bind0[/VALUES ?series/] bind0-->v3 bind00(["wd:Q18844732"]) bind00 --> bind0 v4 --"p:direct/P31"--> c2 v4 --"p:P179"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:qualifier/P1545".-> v2 end v5 --"p:statement/P179"--> v3 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P2364".-> v1 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P4908".-> v6 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end