query-5bcdcfad73177397d68547e77cadcd71

rq turtle/ttl

Companies with largest revenue in USD (Q4917) SELECT ?item ?revenue ?unit ?revenue_USD ?date WHERE { ?item wdt:P31/wdt:P279* wd:Q4830453; p:P2139 ?statement . OPTIONAL { ?item wdt:P159 ?hq } . ?statement wikibase:rank ?rank . FILTER( ?rank != wikibase:DeprecatedRank ) . OPTIONAL { FILTER( ?rank != wikibase:PreferredRank ) . ?item p:P2139 ?statement1 . ?statement1 wikibase:rank wikibase:PreferredRank . FILTER( ?statement1 != ?statement ) . } . FILTER( !BOUND( ?statement1 ) ) . OPTIONAL { ?statement pq:P585 ?date } . { ?statement psv:P2139 [ wikibase:quantityAmount ?revenue; wikibase:quantityUnit wd:Q4917 ] . BIND( wd:Q4917 AS ?unit ) . BIND( ?revenue AS ?revenue_USD ) . } UNION { ?statement psv:P2139 [ wikibase:quantityAmount ?revenue; wikibase:quantityUnit ?unit ] . FILTER( ?unit != wd:Q4917 ) . ?unit p:P2284 ?unit_statement . ?unit_statement wikibase:rank ?unit_rank; psv:P2284 [ wikibase:quantityUnit wd:Q4917; wikibase:quantityAmount ?usd ] . FILTER( ?unit_rank != wikibase:DeprecatedRank ) . OPTIONAL { FILTER( ?unit_rank != wikibase:PreferredRank ) . ?unit p:P2284 ?unit_statement1 . ?unit_statement1 psv:P2284/wikibase:quantityUnit wd:Q4917; wikibase:rank wikibase:PreferredRank . FILTER( ?unit_statement1 != ?unit_statement ) . } . FILTER( !BOUND( ?unit_statement1 ) ) . BIND( ?revenue * ?usd AS ?revenue_USD ) . } . } ORDER BY DESC(?revenue_USD) LIMIT 10

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
#Companies with largest revenue in USD (Q4917)
SELECT ?item ?revenue ?unit ?revenue_USD ?date WHERE {
  ?item wdt:P31/wdt:P279* wd:Q4830453;
        p:P2139 ?statement .
  OPTIONAL { ?item wdt:P159 ?hq } .
  ?statement wikibase:rank ?rank .
  FILTER( ?rank != wikibase:DeprecatedRank ) .
  OPTIONAL {
    FILTER( ?rank != wikibase:PreferredRank ) .
    ?item p:P2139 ?statement1 .
    ?statement1 wikibase:rank wikibase:PreferredRank .
    FILTER( ?statement1 != ?statement ) .
  } .
  FILTER( !BOUND( ?statement1 ) ) .
  OPTIONAL { ?statement pq:P585 ?date } .
  {
    ?statement psv:P2139 [
      wikibase:quantityAmount ?revenue; wikibase:quantityUnit wd:Q4917
    ] .
    BIND( wd:Q4917 AS ?unit ) .
    BIND( ?revenue AS ?revenue_USD ) .
  } UNION {
    ?statement psv:P2139 [
      wikibase:quantityAmount ?revenue; wikibase:quantityUnit ?unit
    ] .
    FILTER( ?unit != wd:Q4917 ) .
    ?unit p:P2284 ?unit_statement .
    ?unit_statement wikibase:rank ?unit_rank;
                    psv:P2284 [ wikibase:quantityUnit wd:Q4917; wikibase:quantityAmount ?usd ] .
    FILTER( ?unit_rank != wikibase:DeprecatedRank ) .
    OPTIONAL {
      FILTER( ?unit_rank != wikibase:PreferredRank ) .
      ?unit p:P2284 ?unit_statement1 .
      ?unit_statement1 psv:P2284/wikibase:quantityUnit wd:Q4917;
                       wikibase:rank wikibase:PreferredRank .
      FILTER( ?unit_statement1 != ?unit_statement ) .
    } .
    FILTER( !BOUND( ?unit_statement1 ) ) .
    BIND( ?revenue * ?usd AS ?revenue_USD ) .
  } .
}
ORDER BY DESC(?revenue_USD)
LIMIT 10

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?date"):::projected v6("?hq") v5("?item"):::projected v3("?rank") v8("?revenue"):::projected v14("?revenue_USD"):::projected v4("?statement") v2("?statement1") v9("?unit"):::projected v11("?unit_rank") v12("?unit_statement") v10("?unit_statement1") v13("?usd") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) c12(["wd:Q4917"]):::iri c2(["wikibase:PreferredRank"]):::iri c5(["wd:Q4830453"]):::iri f0[["not bound(?statement1)"]] f0 --> v2 f1[["?rank != 'wikibase:DeprecatedRank'"]] f1 --> v3 v5 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c5 v5 --"p:P2139"--> v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:direct/P159".-> v6 end v4 --"wikibase:rank"--> v3 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:P2139".-> v2 v2 --"wikibase:rank"--> c2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P585".-> v7 end subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; f2[["not bound(?unit_statement1)"]] f2 --> v10 f3[["?unit_rank != 'wikibase:DeprecatedRank'"]] f3 --> v11 f4[["?unit != 'wd:Q4917'"]] f4 --> v9 a3 --"wikibase:quantityAmount"--> v8 a3 --"wikibase:quantityUnit"--> v9 v4 --"p:statement/value/P2139"--> a3 v9 --"p:P2284"--> v12 v12 --"wikibase:rank"--> v11 a4 --"wikibase:quantityUnit"--> c12 a4 --"wikibase:quantityAmount"--> v13 v12 --"p:statement/value/P2284"--> a4 subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:P2284".-> v10 v10 --"p:statement/value/P2284"--> a5 a5 --"wikibase:quantityUnit"--> c12 v10 --"wikibase:rank"--> c2 end bind5[/"?revenue * ?usd"/] v8 --o bind5 v13 --o bind5 bind5 --as--o v14 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; a2 --"wikibase:quantityAmount"--> v8 a2 --"wikibase:quantityUnit"--> c12 v4 --"p:statement/value/P2139"--> a2 bind6[/"'wd:Q4917'"/] bind6 --as--o v9 bind7[/"?revenue"/] v8 --o bind7 bind7 --as--o v14 end union0r <== or ==> union0l end