Skip to content

Commit e104007

Browse files
authored
Create SQL Exercises: Find the salesmen and customers with their name and cities, who belongs to the same city
1 parent 809b537 commit e104007

1 file changed

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

0 commit comments

Comments
 (0)