query-b30e45d25b94abd04948631c0080cf0c

rq turtle/ttl

List of company revenuesI'm trying to come up with a query to retrieve the revenues of Russian companies. This is what I got so far:

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 ?company ?companyLabel ?revenue ?revDate ?fedSubjectLabel
WHERE 
{
  ?company wdt:P31/wdt:P279* wd:Q4830453; #all businesses
           wdt:P159/wdt:P131* wd:Q911. #located in Ufa - using Q649 will time out the query
  OPTIONAL {
    ?company p:P2139 [ ps:P2139 ?revenue; pq:P585 ?revDate].
    FILTER(YEAR(?revDate) = 2016).  
    }
  ?company wdt:P159 ?town.
  ?town wdt:P131 ?fedSubject.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,ru". }
}
LIMIT 100

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?company"):::projected v5("?fedSubject") v1("?revDate"):::projected v3("?revenue"):::projected v4("?town") a1((" ")) a2((" ")) a3((" ")) c14(["en,ru"]):::literal c4(["wd:Q4830453"]):::iri c12(["bd:serviceParam"]):::iri c7(["wd:Q911"]):::iri v2 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c4 v2 --"p:direct/P159"--> a2 a2 --"p:direct/P131"--> c7 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; a3 -."p:statement/P2139".-> v3 a3 --"p:qualifier/P585"--> v1 v2 --"p:P2139"--> a3 end v2 --"p:direct/P159"--> v4 v4 --"p:direct/P131"--> v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c12 --"wikibase:language"--> c14 end