query-82b74967afdc407bd9f6dfc6da52be9d

rq turtle/ttl

Stars up to 18 light years away sorted by the nearest SELECT ?star ?starLabel ?distance ?unitLabel ?lightyears WHERE { { SELECT ?star ?distance ?unit ?lightyears WHERE { ?star wdt:P31 wd:Q523. ?star p:P2583/psv:P2583 ?statement. ?statement wikibase:quantityUnit ?unit. ?statement wikibase:quantityAmount ?distance. ?statement wikibase:quantityNormalized/wikibase:quantityAmount ?distanceNormalized. # convert to normalized unit (meter) BIND (?distanceNormalized / 9460800000000000 AS ?lightyears) FILTER( ?lightyears < 19) } LIMIT 100 } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } } ORDER BY ?lightyears LIMIT 100

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Stars up to 18 light years away sorted by the nearest
SELECT ?star ?starLabel ?distance ?unitLabel ?lightyears
WHERE
{
  {
    SELECT ?star ?distance ?unit ?lightyears
    WHERE
    {
      ?star wdt:P31 wd:Q523.
      ?star p:P2583/psv:P2583 ?statement.
      ?statement wikibase:quantityUnit ?unit.
      ?statement wikibase:quantityAmount ?distance.
      ?statement wikibase:quantityNormalized/wikibase:quantityAmount ?distanceNormalized. # convert to normalized unit (meter)
      BIND (?distanceNormalized / 9460800000000000  AS ?lightyears)
      FILTER( ?lightyears < 19)
    }
    LIMIT 100
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY ?lightyears
LIMIT 100

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?distance"):::projected v6("?distanceNormalized") v7("?lightyears"):::projected v2("?star"):::projected v3("?statement") v4("?unit") a1((" ")) a2((" ")) c3(["wd:Q523"]):::iri c10(["bd:serviceParam"]):::iri c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?lightyears < '19^^xsd:integer'"]] f0 --> v7 v2 --"p:direct/P31"--> c3 v2 --"p:P2583"--> a1 a1 --"p:statement/value/P2583"--> v3 v3 --"wikibase:quantityUnit"--> v4 v3 --"wikibase:quantityAmount"--> v5 v3 --"wikibase:quantityNormalized"--> a2 a2 --"wikibase:quantityAmount"--> v6 bind1[/"?distanceNormalized / '9460800000000000^^xsd:integer'"/] v6 --o bind1 bind1 --as--o v7 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end