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

2370 단어 leetcodeleetcode

문제


풀이

  • 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

좋은 웹페이지 즐겨찾기