w3resource logo
SQL Exercises

SQL Exercises with Solution - VIEW

SQL [16 exercises with solution]

1. Write a query to create a view for those salesmen belongs to the city New York. 

Sample table: salesman

Click me to see the solution

2. Write a query to create a view for all salesmen with columns salesman_id, name, and city. 

Sample table: salesman

Click me to see the solution

3. Write a query to find the salesmen of the city New York who achieved the commission more than 13%. 

Sample table: salesman

Click me to see the 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 table: customer


Click me to see the solution

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

Sample table : orders


Click me to see the solution

6. Write a query to create a view that shows for each order the salesman and customer by name. 

Sample table: salesman


Sample table: customer


Sample table: orders


Click me to see the solution

7. Write a query to create a view that finds the salesman who has the customer with the highest order of a day. 

Sample table: salesman


Sample table: orders


Click me to see the 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: salesman


Click me to see the solution

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

Sample table: customer


Click me to see the solution

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

Sample table: salesman


Click me to see the solution

11. 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)


Sample table: salesman


Sample table: orders


Click me to see the solution

12. Write a query to create a view that shows each salesman with more than one customers.

Sample table: salesman


Sample table: customer


Click me to see the solution

13. Write a query to create a view that shows all matches of customers with salesman such that at least one customer in the city of customer served by a salesman in the city of the salesman.

Sample table: salesman


Sample table: customer


Click me to see the solution

14. Write a query to create a view that shows the number of orders in each day.

Sample table: orders


Click me to see the solution

15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.

Sample table: salesman


Sample table: orders


Click me to see the solution

16. Write a query to create a view that finds the salesmen who issued orders on either August 17th, 2012 or October 10th, 2012.

Sample table: orders


Click me to see the solution