query-b3a885fbde576eb1b0e54dca77f5d926

rq turtle/ttl

Alexjorm

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#>
SELECT DISTINCT 
  (?company AS ?companyID)
  ?companyLabel
  ?locationLabel
  (?city AS ?cityID)
  ?cityLabel
  ?stateLabel
WHERE 
{
  VALUES ?company {wd:Q312 wd:Q3884 wd:Q2283 wd:Q380 wd:Q95}

  ?company p:P159 ?HQ_statement .
  ?HQ_statement a wikibase:BestRank . # truthy statements only
  ?HQ_statement ps:P159 ?city . # company hq location

  OPTIONAL { ?HQ_statement pq:P276 ?location . } # qualifier for HQ's location

  ?city wdt:P131+ ?state . # located in territorial entity
  ?state wdt:P31 wd:Q35657 . # territorial entity is instance of 'state'

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?company ?companyLabel ?locationLabel ?city ?cityLabel ?stateLabel ?ceo
ORDER BY ASC(?companyLabel)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?HQ_statement") v4("?city"):::projected v8("?cityID") v2("?company"):::projected v7("?companyID") v1("?companyLabel"):::projected v5("?location") v6("?state") c10(["bd:serviceParam"]):::iri c3(["wikibase:BestRank"]):::iri c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal c8(["wd:Q35657"]):::iri bind0[/VALUES ?company/] bind0-->v2 bind00(["wd:Q312"]) bind00 --> bind0 bind01(["wd:Q3884"]) bind01 --> bind0 bind02(["wd:Q2283"]) bind02 --> bind0 bind03(["wd:Q380"]) bind03 --> bind0 bind04(["wd:Q95"]) bind04 --> bind0 v2 --"p:P159"--> v3 v3 --"a"--> c3 v3 --"p:statement/P159"--> v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P276".-> v5 end v4 --"p:direct/P131"--> v6 v6 --"p:direct/P31"--> c8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end bind1[/"?company"/] v2 --o bind1 bind1 --as--o v7 bind2[/"?city"/] v4 --o bind2 bind2 --as--o v8