[183_EASY] Customers Who Never Order

2022. 9. 25. 22:31·SQL/LeetCode

 

 

Customers Who Never Order - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

Table: Customers

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| id          | int     |
| name        | varchar |
+-------------+---------+
id is the primary key column 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 for this table.
customerId is a foreign key 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 an SQL query to report all customers who never order anything.

Return the result table in any order.

The query 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       |
+-----------+

 

문제 조건 

주문한 적이 없는 모든 고객을 출력하시오. 

 

문제 풀이

select c.name as 'Customers'
from customers c
    left join orders o on c.id = o.customerId
where o.customerId is null
저작자표시 (새창열림)

'SQL > LeetCode' 카테고리의 다른 글

[180_MEDIUM] Consecutive Numbers 다시풀기  (0) 2022.09.26
[197_EASY] Rising Temperature  (0) 2022.09.25
[178_MEDIUM] Rank Scores  (0) 2022.09.23
[177_MEDIUM] Nth Highest Salary  (0) 2022.09.23
[176_MEDIUM] Second Highest Salary  (0) 2022.09.23
'SQL/LeetCode' 카테고리의 다른 글
  • [180_MEDIUM] Consecutive Numbers 다시풀기
  • [197_EASY] Rising Temperature
  • [178_MEDIUM] Rank Scores
  • [177_MEDIUM] Nth Highest Salary
소금깨
소금깨
  • 소금깨
    고군분투 인생살이
    소금깨
  • 전체
    오늘
    어제
    • 분류 전체보기 (328)
      • SQL (271)
        • 프로그래머스 (27)
        • LeetCode (198)
        • Hacker Rank (27)
        • Solve SQL (1)
        • 개념 (15)
      • 데이터 분석 (16)
        • 참고하며 공부하기 (14)
      • 기타 (15)
        • 통계 (14)
      • 오류 (6)
      • 인생살이 (0)
        • 리뷰 (0)
        • 일기 (0)
      • 中文 (0)
      • TABLEAU (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    패스트캠퍼스
    HACKER_RANK
    solvesql
    Hard
    파이썬을활용한시계열데이터분석AtoZ올인원패키지Online
    프로그래머스
    직장인인강
    LeetCode
    MySQL
    직장인자기계발
    시계열데이터분석
    SQL
    패스트캠퍼스후기
    해커랭크
    medium
    프리미엄
    파이썬을활용한시계열데이터분석
    easy
    group by
    패캠챌린지
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
소금깨
[183_EASY] Customers Who Never Order
상단으로

티스토리툴바