w3resource
SQL exercises

SQL VIEW Exercises: Create a view that shows the number of the salesman in each city

SQL VIEW : Exercise-10 with Solution

10. Write a query to create a view that shows the number of the salesman in each city.

Sample table: salesman


Sample Solution:

CREATE VIEW citynum
AS SELECT city, COUNT (DISTINCT salesman_id)
FROM salesman
GROUP BY city;

output:

sqlpractice-# FROM citynum;
   city   | count
----------+-------
 London   |     1
 New York |     1
 Paris    |     2
 Rome     |     1
          |     1
(5 rows)

Inventory database model:

Inventory database model

Contribute your code and comments through Disqus.

Previous: Write a query to create a view that shows all of the customers who have the highest grade.
Next: Write a query to create a view that shows the average and total orders for each salesman after his or her name. (Assume all names are unique)

What is the difficulty level of this exercise?



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