[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)
  • 블로그 메뉴

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

  • 공지사항

  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.