LeetCode/릿코드-Customers Who Never Order-MySQL

cosmos·2021년 9월 23일
0
post-thumbnail
post-custom-banner

문제


풀이

  • write an sql query to report all customers who never order anthing.
  • return the result table in any order.
  • the query result format is in the following example.

코드

-- leetcode, Customers Who Never Order, mysql

-- 서브쿼리를 이용한 풀이
SELECT Name AS Customers
FROM Customers
WHERE Id NOT IN (SELECT CustomerId
                 FROM Orders)

-- 조인을 이용한 풀이
SELECT C.Name AS Customers
FROM Customers AS C
LEFT OUTER JOIN Orders AS O ON C.ID = O.CustomerId
WHERE O.Id IS NULL

결과


출처 && 깃허브

leetcode
github

post-custom-banner

0개의 댓글