๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐ŸŒฎ ๐Ÿ’ฌ

๐Ÿ’ป 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.