w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the country ID and number of cities in that country we have

SQL SORTING and FILTERING on HR Database: Exercise-25 with Solution

25. Write a query in SQL to display the country ID and number of cities in that country we have.

Sample table : locations


Sample Solution:

SELECT country_id,  COUNT(*)  
	FROM locations 
		GROUP BY country_id;

Sample Output:

 country_id | count
------------+-------
 CH         |     2
 "          |     1
 US         |     4
 AU         |     1
 IT         |     2
 Ox         |     1
 JP         |     2
 CA         |     2
 DE         |     1
 NL         |     1
 SG         |     1
 CN         |     1
 UK         |     2
 IN         |     1
 BR         |     1
(15 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the country ID and number of cities in that country we have - Duration

Rows:

Query visualization of Display the country ID and number of cities in that country we have - Rows

Cost:

Query visualization of Display the country ID and number of cities in that country we have - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.
Next: Write a query in SQL to display the manager ID and number of employees managed by the manager.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming