2

I have data corpus like:

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

and I want result like:

DistCountries    DeviceCount
country_1        3
country_2        3

I have used following query to extract distinct country list:

SELECT DISTINCT(Country) as DistCountries FROM devices;

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.

1 Answer 1

4

Try:

SELECT country, count(*) 
FROM devices
GROUP BY country;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.