w3resource
SQL exercises

SQL VIEW Exercises: Create a view to get a count of how many customers we have at each level of grade

SQL VIEW: Exercise-4 with Solution

4. Write a query to create a view to getting a count of how many customers we have at each level of a grade.

Sample table: customer


Sample Solution:

CREATE VIEW gradecount (grade, number)
AS SELECT grade, COUNT(*)
FROM customer
GROUP BY grade;

output:

sqlpractice=# SELECT *
sqlpractice-# FROM gradecount
sqlpractice-# WHERE number = 2;
 grade | number
-------+--------
       |      2
   200 |      2
   300 |      2
(3 rows)

Inventory database model:

Inventory database model

Contribute your code and comments through Disqus.

Previous: Write a query to find the salesmen of the city New York who achieved the commission more than 13%.
Next: Write a query to create a view to keeping track the number of customers ordering number of salesmen attached, average amount of orders and the total amount of orders in a day.

What is the difficulty level of this exercise?



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