SQL Exercises: Short out the customer and their grade who made an order
SQL Query on Multiple Tables : Exercise-5 with Solution
Write a SQL statement that shorts out the customer and their grade who made an order. Each of the customers must have a grade and served by at least a salesman, who belongs to a city.
Sample table: salesman
Sample table: customer
Sample table: orders
SELECT customer.cust_name AS "Customer", customer.grade AS "Grade" FROM orders, salesman, customer WHERE orders.customer_id = customer.customer_id AND orders.salesman_id = salesman.salesman_id AND salesman.city IS NOT NULL AND customer.grade IS NOT NULL;
Output of the query:
Customer Grade Nick Rimando 100 Geoff Cameron 100 Brad Davis 200 Nick Rimando 100 Fabian Johnson 300 Geoff Cameron 100 Jozy Altidor 200 Nick Rimando 100 Graham Zusi 200 Graham Zusi 200 Julian Green 300
Pictorial presentation :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a SQL statement that finds out each order number followed by the name of the customers who made the order.
Next: Write a query that produces all customers with their name, city, salesman and commission, who served by a salesman and the salesman works at a rate of the commission within 12% to 14%.
What is the difficulty level of this exercise?