8000 update code · dana3601/Leetcode-Problems@8f5425f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f5425f

Browse files
committed
update code
1 parent 498b3ba commit 8f5425f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Order and Deliver/# 607. Sales Person.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 607. Sales Person
22

33
# Output all the names in the table salesperson, who didn’t have sales to company 'RED'
4+
# Don't forgot to use DISTINCT to avoid duplicate
5+
46

57
SELECT DISTINCT s.name AS name
68
FROM salesperson s
@@ -9,3 +11,10 @@ WHERE s.sales_id NOT IN (
911
FROM orders o
1012
JOIN company c ON o.com_id = c.com_id WHERE c.name = "RED")
1113

14+
# or
15+
# Will join three table in a row is easier to understand
16+
SELECT DISTINCT p.name AS name
17+
FROM salesperson p LEFT JOIN orders o USING sales_id
18+
LEFT JOIN company c USING com_id
19+
WHERE c.name != “RED”
20+
;
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# 1350. Students With Invalid Departments
2-
2+
# Find the id and the name of all students who are enrolled in departments that no longer exists
33
SELECT s.id, s.name
44
FROM Students s
5+
# Because the SELECT information is from Student table
56
LEFT JOIN Departments d ON d.id = s.department_id
67
WHERE d.name IS NULL
78
;
9+
10+
# or
11+
# Has to use LEFT JOIN?
12+
SELECT s.id, s.name
13+
FROM department d, students s
14+
WHERE d.id = s.department_id
15+
AND d.name IS NULL
16+
;

0 commit comments

Comments
 (0)
0