Skip to content

Commit 3247c8a

Browse files
authored
Create SQL Exercises: Make a list of customers who appointed a salesman for their jobs who does not live in the same city where their customer lives, and gets a commission is above 12%
1 parent 3fcc8a7 commit 3247c8a

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
https://www.w3resource.com/sql-exercises/sql-joins-exercise-5.php
2+
3+
SQL JOINS: Exercise-5 with Solution
4+
From the following tables write a SQL query to find those salespersons do not live in the same city where their customers live and received a commission from the company more than 12%. Return Customer Name, customer city, Salesman, salesman city, commission.
5+
6+
Sample table: salesman
7+
salesman_id | name | city | commission
8+
-------------+------------+----------+------------
9+
5001 | James Hoog | New York | 0.15
10+
5002 | Nail Knite | Paris | 0.13
11+
5005 | Pit Alex | London | 0.11
12+
5006 | Mc Lyon | Paris | 0.14
13+
5007 | Paul Adam | Rome | 0.13
14+
5003 | Lauson Hen | San Jose | 0.12
15+
16+
Sample table: customer
17+
customer_id | cust_name | city | grade | salesman_id
18+
-------------+----------------+------------+-------+-------------
19+
3002 | Nick Rimando | New York | 100 | 5001
20+
3007 | Brad Davis | New York | 200 | 5001
21+
3005 | Graham Zusi | California | 200 | 5002
22+
3008 | Julian Green | London | 300 | 5002
23+
3004 | Fabian Johnson | Paris | 300 | 5006
24+
3009 | Geoff Cameron | Berlin | 100 | 5003
25+
3003 | Jozy Altidor | Moscow | 200 | 5007
26+
3001 | Brad Guzan | London | | 5005
27+
28+
29+
# Solution
30+
select a.cust_name as "Customer Name", a.city, b.name as"Salesman", b.commission
31+
from customer as a
32+
join salesman as b ON a.salesman_id=b.salesman_id
33+
where b.commission >.12 and a.city <> b.city
34+
;

0 commit comments

Comments
 (0)