From 2741a2c93c63b8ee7ec5521fb112c37afe66e6b4 Mon Sep 17 00:00:00 2001 From: ivanbyone Date: Wed, 2 Jul 2025 12:26:35 +0300 Subject: [PATCH] task: #607 --- README.md | 1 + leetcode/easy/607. Sales Person.sql | 67 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 leetcode/easy/607. Sales Person.sql diff --git a/README.md b/README.md index 8f328a2..60f8285 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Have a good contributing! - [586. Customer Placing the Largest Number of Orders](./leetcode/easy/586.%20Customer%20Placing%20the%20Largest%20Number%20of%20Orders.sql) - [595. Big Countries](./leetcode/easy/595.%20Big%20Countries.sql) - [596. Classes With at Least 5 Students](./leetcode/easy/596.%20Classes%20With%20at%20Least%205%20Students.sql) + - [607. Sales Person](./leetcode/easy/607.%20Sales%20Person.sql) - [610. Triangle Judgement](./leetcode/easy/610.%20Triangle%20Judgement.sql) - [619. Biggest Single Number](./leetcode/easy/619.%20Biggest%20Single%20Number.sql) - [620. Not Boring Movies](./leetcode/easy/620.%20Not%20Boring%20Movies.sql) diff --git a/leetcode/easy/607. Sales Person.sql b/leetcode/easy/607. Sales Person.sql new file mode 100644 index 0000000..18dbcfe --- /dev/null +++ b/leetcode/easy/607. Sales Person.sql @@ -0,0 +1,67 @@ +/* +Question 607. Sales Person +Link: https://leetcode.com/problems/sales-person/description/ + +Table: SalesPerson + ++-----------------+---------+ +| Column Name | Type | ++-----------------+---------+ +| sales_id | int | +| name | varchar | +| salary | int | +| commission_rate | int | +| hire_date | date | ++-----------------+---------+ +sales_id is the primary key (column with unique values) for this table. +Each row of this table indicates the name and the ID of a salesperson alongside their salary, commission rate, and hire date. + + +Table: Company + ++-------------+---------+ +| Column Name | Type | ++-------------+---------+ +| com_id | int | +| name | varchar | +| city | varchar | ++-------------+---------+ +com_id is the primary key (column with unique values) for this table. +Each row of this table indicates the name and the ID of a company and the city in which the company is located. + + +Table: Orders + ++-------------+------+ +| Column Name | Type | ++-------------+------+ +| order_id | int | +| order_date | date | +| com_id | int | +| sales_id | int | +| amount | int | ++-------------+------+ +order_id is the primary key (column with unique values) for this table. +com_id is a foreign key (reference column) to com_id from the Company table. +sales_id is a foreign key (reference column) to sales_id from the SalesPerson table. +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. + + +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. +*/ + +WITH red_orders AS +( + SELECT o.sales_id + FROM Orders AS o + LEFT JOIN + Company AS c + ON o.com_id = c.com_id + WHERE c.name = 'RED' +) + +SELECT name +FROM SalesPerson +WHERE sales_id NOT IN (SELECT r.sales_id FROM red_orders AS r)