title: SPARQL and counting items
body: <p>I'm using SPARQL and Wikidata query service to try and determine: <em>The actors that got the Oscar award sorted by the total number of (any) awards they received in decreasing order with the list of all their awards.</em></p>
  <p>So far this is what I have that works but doesn't quite do what the question is asking.</p>
  <pre><code>SELECT ?item ?itemLabel
  WHERE {
    ?item wdt:P31 wd:Q5 .
    ?item wdt:P166 wd:Q103916 .
    SERVICE wikibase:label { bd:serviceParam wikibase:language &quot;[AUTO_LANGUAGE],en&quot;. }
  }
  
  LIMIT 1000
  </code></pre>
  <p>And this I what I have that I am trying to get to work but is not yet working. Im new to this and any help is appreciated. <em>Updated below query because I've gotten a bit closer</em></p>
  <pre><code>SELECT ?item ?itemLabel (COUNT (DISTINCT ?year) AS ?count)
  WHERE {
    ?item wdt:P31 wd:Q5 .
    ?item wdt:P166 wd:Q103916 .
    ?item p:P585 ?year .
    SERVICE wikibase:label { bd:serviceParam wikibase:language &quot;[AUTO_LANGUAGE],en&quot;. }
  }
  GROUP BY ?item ?itemLabel
  ORDER BY ?count
  LIMIT 100
  </code></pre>