0

I have a table like

Name      CountryCode 
kabul       AFG
herat       AFG
haag        NLD
tilburg     NLD
breda       NLD
mumbai      IND
delhi       IND
chennai     IND

if want to get the count of city for CountryCode AFG so i will right query select Count(Name) from city where CountryCode = AFG; and i will get the result

Count(Name)
        2

but if I want count for CountryCode AFG,NLD,IND in single query like

count(Name)
        2
        3
        3

How should I write the query to get above result?

1
  • i don't know a city called haag in the netherlands. the netherlands does have a city called den haag Commented Apr 6, 2018 at 17:40

2 Answers 2

3
SELECT CountryCode, COUNT(*) 
FROM table 
WHERE CountryCode IN ('AFG','NLD','IND') 
GROUP BY CountryCode;
Sign up to request clarification or add additional context in comments.

1 Comment

Should be WHERE CountryCode IN ('AFG','NLD','IND')
0

So if I understand the question correctly this should work

SELECT COUNT (*) FROM myTable 
  WHERE CountryCode = 'AFG'
  OR CountryCode = 'NLD'
  OR CountryCode = 'IND' 

1 Comment

That will get the number of rows with one of those CountryCodes, but not the count of each of the three.

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.