title: SQL query instead of loop
body: <p>I have data corpus like:</p>
  
  <pre><code>DeviceID     Country
  id_1         country_1
  id_2         country_1
  id_3         country_1
  id_4         country_2
  id_5         country_2
  id_6         country_2
  </code></pre>
  
  <p>and I want result like:</p>
  
  <pre><code>DistCountries    DeviceCount
  country_1        3
  country_2        3
  </code></pre>
  
  <p>I have used following query to extract distinct country list:</p>
  
  <pre><code>SELECT DISTINCT(Country) as DistCountries FROM devices;
  </code></pre>
  
  <p>But, I don't know what can be done to get the required results. Can this be done instead of loops? Any help would be appreciated.</p>