inblog logo
|
stupefyee
    SQL문제풀기

    [SQL 문제 풀이] Customers Who Never Order (주문하지 않는 고객)

    Stupefyee's avatar
    Stupefyee
    May 26, 2025
    [SQL 문제 풀이] Customers Who Never Order (주문하지 않는 고객)
    Contents
    내가 작성한 쿼리
    Customers Who Never Order - LeetCode
    Can you solve this real interview question? Customers Who Never Order - Table: Customers +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | +-------------+---------+ id is the primary key (column with unique values) for this table. Each row of this table indicates the ID and name of a customer.   Table: Orders +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | customerId | int | +-------------+------+ id is the primary key (column with unique values) for this table. customerId is a foreign key (reference columns) of the ID from the Customers table. Each row of this table indicates the ID of an order and the ID of the customer who ordered it.   Write a solution to find all customers who never order anything. Return the result table in any order. The result format is in the following example.   Example 1: Input: Customers table: +----+-------+ | id | name | +----+-------+ | 1 | Joe | | 2 | Henry | | 3 | Sam | | 4 | Max | +----+-------+ Orders table: +----+------------+ | id | customerId | +----+------------+ | 1 | 3 | | 2 | 1 | +----+------------+ Output: +-----------+ | Customers | +-----------+ | Henry | | Max | +-----------+
    Customers Who Never Order - LeetCode
    https://leetcode.com/problems/customers-who-never-order/description/
    Customers Who Never Order - LeetCode
    notion image
    아무것도 주문하지 않는 모든 고객을 찾기 위해 솔루션을 사용하십시오. 결과 테이블을 반환합니다.
     

    내가 작성한 쿼리

    MySQL, Oracle

    SELECT C.name AS Customers FROM Customers C LEFT JOIN Orders O ON C.id = O.customerId WHERE O.customerId IS NULL;
    Share article
    Contents
    내가 작성한 쿼리

    stupefyee

    RSS·Powered by Inblog