Sales Person - LeetCode

Pepzera·2026년 1월 28일

SQL코딩테스트

목록 보기
7/18

Sales Person 문제

출처 : LeetCode Sales Person

Table : SalesPerson

Colume NameType
sales_idint
namevarchar
salaryint
commission_rateint
hire_datedate

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

Colume NameType
com_idint
namevarchar
cityvarchar

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

Colume NameType
order_idint
order_datedate
com_idint
sales_idint
amountint

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.

Q.

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.


질문

회사 이름이 RED인 회사와 단 한 번도 거래하지 않은 영업사원(SalesPerson)의 이름을 구하라!

내 답안 📕

SELECT name
FROM SalesPerson
WHERE sales_id NOT IN (SELECT O.sales_id
                       FROM Company AS C
                         INNER JOIN Orders AS O ON C.com_id = O.com_id
                       WHERE C.name = 'RED')

0개의 댓글