w3resource
SQL exercises

SQL VIEW Exercises: Create a view that shows all of the customers who have the highest grade

SQL VIEW: Exercise-9 with Solution

9. Write a query to create a view that shows all of the customers who have the highest grade.

Sample table: customer


Sample Solution:

CREATE VIEW highgrade
  AS SELECT *
  FROM customer
  WHERE grade =
    (SELECT MAX (grade)
     FROM customer);

output:

sqlpractice=# SELECT *
sqlpractice-# FROM highgrade;
 customer_id | cust_name |  city  | grade | salesman_id
-------------+-----------+--------+-------+-------------
        1234 | Jose      | Dallas |   500 |        5001
(1 row)

Inventory database model:

Inventory database model

Contribute your code and comments through Disqus.

Previous: Write a query to create a view that finds the salesman who has the customer with the highest order at least 3 times on a day.
Next: Write a query to create a view that shows the number of the salesman in each city.

What is the difficulty level of this exercise?



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