๐ป leetcode/database13 [LeetCode] Database | 183. Customers Who Never Order Problem Example Thinking ์ฐ์ LEFT JOIN์ผ๋ก Customers์ ๋์ํ๋ Order์ ๋ณด๋ฅผ ๋ชจ๋ ๊ฐ์ ธ์จ๋ค. Order ์ ๋ณด๊ฐ ์์ ๊ฒฝ์ฐ์๋ Null๋ก ํ์๊ฐ ๋๋, LEFT JOINํ ํ ์ด๋ธ์์ where ์ ๋ก Order ํ ์ด๋ธ์ id๋ customerId๊ฐ null์ธ ์กฐ๊ฑด์ ์ถ๊ฐํด์ฃผ์ Solve ์ ์ถ ๋ต์ select c.name as Customers from Customers as c LEFT JOIN Orders as o on c.id = o.customerId where o.customerId is null # where o.id is null ๋ ๊ฐ๋ฅ https://leetcode.com/problems/customers-who-never-order/submission.. 2022. 1. 2. [LeetCode] Database | 182. Duplicate Emails Problem Example Thinking ํ ์ด๋ธ์์ ์ค๋ณต์ด ๋๋ ์ด๋ฉ์ผ์ ์ถ๋ ฅํด์ฃผ๋ฉด ๋๋ค. ์ค๋ณต๋ ์ด๋ฉ์ผ์ GROUP BY๋ก ๋ฌถ์ด์ฃผ๊ณ HAVING์ ์ฌ์ฉํด์ count ๊ฐ์ด 1 ์ด๊ณผ (ํน์ 2 ์ด์)์ธ email ๊ฐ์ ๊ณจ๋ผ์ฃผ์ Solve ์ ์ถ ๋ต์ select email as Email from Person GROUP BY email HAVING COUNT(*) > 1; https://leetcode.com/problems/duplicate-emails/submissions/ Duplicate Emails - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge.. 2022. 1. 2. [LeetCode] Database | 181. Employees Earning More Than Their Manager Problem Example Thinking input ํ ์ด๋ธ์ ํ์ธํ๋ฉด Joe์ ๋งค๋์ ๋ managerId๊ฐ 3์ด๋ฏ๋ก id๊ฐ 3์ธ Sam์ด Joe์ ๋งค๋์ ์ด๊ณ , Henry๋ ๋๊ฐ์ ๊ณผ์ ์ ๊ฑฐ์ณ Max๊ฐ ๋งค๋์ ์์ ์ ์ ์๋ค. managerId๊ฐ null์ธ Sam๊ณผ Max๋ ๋งค๋์ ์ด๋ค. ๋์ผ ํ ์ด๋ธ ๊ฐ์ ์กฐ์ธ์ ์ํด์ self join์ ์ฌ์ฉํ์! Solve ์ ์ถ ๋ต์ select e1.name as Employee from Employee as e1 INNER JOIN Employee as e2 on e1.managerId = e2.id where e1.salary > e2.salary https://leetcode.com/problems/employees-earning-more-than-their-.. 2022. 1. 2. [LeetCode] Database | 175. Combine Two Tables Problem Example Thinking Output์ ํ์ธํ๋ฉด person table์ ์๋ ํ์๋ค์ ๋์ดํ๊ณ ๊ทธ ํ์์ ํด๋นํ๋ (personId๊ฐ ๋์ผํ) city, state ์ ๋ณด๋ฅผ ๊ฐ์ ธ์์ ํ ์ด๋ธ์ ์์ฑ์์ผฐ๋ค. Address ์ ๋ณด๊ฐ ์๋ ํ์์ผ ๊ฒฝ์ฐ์๋ Null๋ก ํ์ ํด์ฃผ์๋ค. ํ ์ด๋ธ์ด 2๊ฐ ์์ผ๋ join์ ํด์ค ๊ฒ์ด๋ฉฐ, ์กฐ์ธ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ(Person table) ์ ๋ณด๋ฅผ ๋ชจ๋ ๊ฐ์ ธ์ฌ ๊ฒ์ด๊ธฐ์ LEFT JOIN์ ์ฌ์ฉํด๋ณด์. Solve ์ ์ถ ๋ต์ select p.firstName, p.lastName, a.city, a.state from Person p left join Address a on p.personId = a.personId https://leetcode.com/problem.. 2021. 12. 29. ์ด์ 1 2 ๋ค์