Skip to content

Commit 0028d25

Browse files
committed
task: #607
1 parent 5f635ba commit 0028d25

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Have a good contributing!
4343
- [586. Customer Placing the Largest Number of Orders](./leetcode/easy/586.%20Customer%20Placing%20the%20Largest%20Number%20of%20Orders.sql)
4444
- [595. Big Countries](./leetcode/easy/595.%20Big%20Countries.sql)
4545
- [596. Classes With at Least 5 Students](./leetcode/easy/596.%20Classes%20With%20at%20Least%205%20Students.sql)
46+
- [607. Sales Person](./leetcode/easy/607.%20Sales%20Person.sql)
4647
- [610. Triangle Judgement](./leetcode/easy/610.%20Triangle%20Judgement.sql)
4748
- [619. Biggest Single Number](./leetcode/easy/619.%20Biggest%20Single%20Number.sql)
4849
- [620. Not Boring Movies](./leetcode/easy/620.%20Not%20Boring%20Movies.sql)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Question 607. Sales Person
3+
Link: https://leetcode.com/problems/sales-person/description/
4+
5+
Table: SalesPerson
6+
7+
+-----------------+---------+
8+
| Column Name | Type |
9+
+-----------------+---------+
10+
| sales_id | int |
11+
| name | varchar |
12+
| salary | int |
13+
| commission_rate | int |
14+
| hire_date | date |
15+
+-----------------+---------+
16+
sales_id is the primary key (column with unique values) for this table.
17+
Each row of this table indicates the name and the ID of a salesperson alongside their salary, commission rate, and hire date.
18+
19+
20+
Table: Company
21+
22+
+-------------+---------+
23+
| Column Name | Type |
24+
+-------------+---------+
25+
| com_id | int |
26+
| name | varchar |
27+
| city | varchar |
28+
+-------------+---------+
29+
com_id is the primary key (column with unique values) for this table.
30+
Each row of this table indicates the name and the ID of a company and the city in which the company is located.
31+
32+
33+
Table: Orders
34+
35+
+-------------+------+
36+
| Column Name | Type |
37+
+-------------+------+
38+
| order_id | int |
39+
| order_date | date |
40+
| com_id | int |
41+
| sales_id | int |
42+
| amount | int |
43+
+-------------+------+
44+
order_id is the primary key (column with unique values) for this table.
45+
com_id is a foreign key (reference column) to com_id from the Company table.
46+
sales_id is a foreign key (reference column) to sales_id from the SalesPerson table.
47+
Each row of this table contains information about one order. This includes the ID of the company, the ID of the salesperson, the date of the order, and the amount paid.
48+
49+
50+
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".
51+
52+
Return the result table in any order.
53+
*/
54+
55+
WITH red_orders AS
56+
(
57+
SELECT o.sales_id
58+
FROM Orders AS o
59+
LEFT JOIN
60+
Company AS c
61+
ON o.com_id = c.com_id
62+
WHERE c.name = 'RED'
63+
)
64+
65+
SELECT name
66+
FROM SalesPerson
67+
WHERE sales_id NOT IN (SELECT r.sales_id FROM red_orders AS r)

0 commit comments

Comments
 (0)