-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsalesPerson.sql
37 lines (37 loc) · 1.04 KB
/
salesPerson.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- +-------------+---------+
-- | Column Name | Type |
-- +-------------+---------+
-- | com_id | int |
-- | name | varchar |
-- | city | varchar |
-- +-------------+---------+
-- Table: Orders
-- +-------------+------+
-- | Column Name | Type |
-- +-------------+------+
-- | order_id | int |
-- | order_date | date |
-- | com_id | int |
-- | sales_id | int |
-- | amount | int |
-- +-------------+------+
-- Write a solution to find the names of all the salespersons who did not have any orders related to the company with the name "RED".
-- Return the result table in any order.
-- The result format is in the following example.
SELECT name
FROM SalesPerson
WHERE sales_id NOT IN (
SELECT sales_id
FROM Orders
WHERE com_id = (
SELECT com_id
FROM Company
WHERE name = 'red'
)
) # OR As a join
SELECT DISTINCT s.name
FROM SalesPerson s
LEFT JOIN Orders o ON s.sales_id = o.sales_id
LEFT JOIN Company c ON o.com_id = c.com_id
WHERE c.name IS NULL
OR c.name != 'RED';