w3resource
SQL exercises

SQL VIEW Exercises: Define a view that finds the salesman who has the customer with the highest order at least 3 times on a day

SQL VIEW : Exercise-8 with Solution

8. 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.

Sample table: customer


Sample table: elitsalesman


Sample Solution:

CREATE VIEW incentive
AS SELECT DISTINCT salesman_id, name
FROM elitsalesman a
WHERE 3 <=
   (SELECT COUNT (*)
    FROM elitsalesman b
    WHERE a.salesman_id = b.salesman_id);

output:

sqlpractice=# SELECT *
sqlpractice-# FROM incentive;
 salesman_id | name
-------------+------------
        5001 | James Hoog 
(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 of a day.
Next: Write a query to create a view that shows all of the customers who have the highest grade.

What is the difficulty level of this exercise?



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