query: embed.html## most gender-imbalanced occupations in ?country citizens
  SELECT ?occupationLabel ?women ?men ?nonbinaries WITH {
    SELECT ?occupation (SUM(?woman) AS ?women) (SUM(?man) AS ?men) (SUM(?nonbinary) AS ?nonbinaries) WHERE {
      BIND(wd:Q30 AS ?country). # substitute country of your choice here (remove the Q30, hit Ctrl+Space and start typing the country name, select the right one from the suggestions with the arrow keys and insert it with Enter)
      ?person wdt:P31 wd:Q5;
              wdt:P27 ?country; # remove this to search world-wide – results in query timeout unless you reduce the dataset in some other fashion
              p:P106/ps:P106 ?occupation.
      { ?person wdt:P21 wd:Q6581097. BIND(1 AS ?man). } UNION
      { ?person wdt:P21 wd:Q2449503. BIND(1 AS ?man). } UNION
      { ?person wdt:P21 wd:Q6581072. BIND(1 AS ?woman). } UNION
      { ?person wdt:P21 wd:Q1052281. BIND(1 AS ?woman). } UNION
      { ?person wdt:P21 wd:Q48270. BIND(1 AS ?nonbinary). } UNION
      { ?person wdt:P21 wd:Q1097630. BIND(1 AS ?nonbinary). }
    }
    GROUP BY ?occupation
  } AS %results WHERE {
    INCLUDE %results. # subquery as optimization: don’t make the label service fetch labels for every ?person in the subquery
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  }
  ORDER BY
    # divide ?variable+1 instead of ?variable to avoid division by zero
    # (unfortunately, we can’t use ABS(LOG(x/y)) instead of the IF() because SPARQL has no LOG function)
    # TODO does not consider ?nonbinaries
    DESC(IF(?women > ?men, (?women+1)/(?men+1), (?men+1)/(?women+1)))
    # if the ratio is the same, show results with more people in total first
    DESC(?women+?men+?nonbinaries)