User:Marbonic

From Wikidata
Jump to navigation Jump to search

This is my very first SPARQL request aiming at listing digital platforms with their economic caracteristics.

SELECT ?firm ?firmLabel ?industry ?industryLabel ?ca ?cap ?ssco ?sscoLabel ?creation ?parent ?parentLabel
WHERE
{
  ?firm wdt:P31/wdt:P279* wd:Q4830453;
            wdt:P452/wdt:P279* ?industry.
   OPTIONAL{?firm wdt:P2139 ?ca.}
   OPTIONAL{?firm wdt:P2226 ?cap.}
   OPTIONAL{?firm wdt:P159 ?ssco.}
   OPTIONAL{?firm wdt:P571 ?creation.}
   OPTIONAL{?firm wdt:P749 ?parent.}

   VALUES ?industry { wd:Q484847 wd:Q75 wd:Q193424 wd:Q483639}.


  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
Try it!


...and here is another request listing flag colors for every country.

SELECT ?drapeau ?drapeauLabel ?couleur ?couleurLabel ?territoire ?territoireLabel ?iso2 ?iso2Label ?iso3 ?iso3Label
WHERE
{
  ?drapeau wdt:P31/wdt:P279* wd:Q186516;
          wdt:P462 ?couleur.
  
   OPTIONAL{?drapeau wdt:P1001 ?territoire.}
   OPTIONAL{?territoire wdt:P297 ?iso2.}
   OPTIONAL{?territoire wdt:P298 ?iso3.}

   VALUES ?couleur {wd:Q3142 wd:Q1088 wd:Q23444 wd:Q3133 wd:Q943 wd:Q23445 wd:Q39338}.
  
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
Try it!

I added a code to generate a map of countries which flag include a given color.

#defaultView:Map

SELECT ?drapeau ?drapeauLabel ?couleur ?couleurLabel ?territoire ?territoireLabel ?coordinates ?coordinatesLabel
WHERE
{
  ?drapeau wdt:P1001 ?territoire;
        wdt:P31 wd:Q186516.
  ?drapeau wdt:P462 ?couleur.
  ?territoire wdt:P625 ?coordinates .
FILTER ( ?couleur in ( wd:Q23445) )    
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
Try it!

For international economists (and other lovers of the gravity equation), you can complete the excellent CEPII distance database for small countries with this simple request. Of course, you need to adapt it by changing the country, here it is for Monaco.

#Country distance vis-à-vis Monaco
SELECT ?place ?placeLabel ?location ?iso2 ?iso2Label ?iso3 ?iso3Label ?distance WHERE {
  wd:Q235 wdt:P625 ?monaco.                         # coordinates of Monaco
   ?place wdt:P31/wdt:P279* wd:Q6256;  
          wdt:P625 ?location.
  BIND(geof:distance(?location, ?monaco) as ?distance).
   OPTIONAL{?place wdt:P297 ?iso2.}
   OPTIONAL{?place wdt:P298 ?iso3.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Try it!

And I drop that here in case somebody is interested in the population-weighted altitude of Switzerland. On sait jamais...


#Ville de Suisse avec leur population et altitude
SELECT ?country ?countryLabel ?population ?citypopulation ?altitude ?city ?cityLabel (?citypopulation * ?altitude / ?totalCityPopulation AS ?altw) {
  ?city wdt:P31 wd:Q515 .
      ?city wdt:P17 ?country .
      ?city wdt:P1082 ?citypopulation .
      ?city wdt:P2044 ?altitude.
      ?country wdt:P1082 ?population.
      VALUES ?country {wd:Q39}.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  {
    SELECT ?country (SUM(?cityPopulation) AS ?totalCityPopulation) WHERE {
      ?city wdt:P31 wd:Q515 .
      ?city wdt:P17 ?country .
      ?city wdt:P1082 ?cityPopulation .
    } GROUP BY ?country
  }
  }
Try it!