SQL 문제풀이

[프로그래머스 SQL] LV.3 대여 기록이 존재하는 자동차 리스트 구하기

냄비짱 2023. 8. 4. 23:14
728x90

❓ Question

❗ Answer

SELECT DISTINCT(car.car_id)
    FROM car_rental_company_car car
    LEFT OUTER JOIN car_rental_company_rental_history history
                ON car.car_id = history.car_id
    WHERE car.car_type = '세단' AND MONTH(history.start_date) = 10
    ORDER BY car.car_id DESC;

📌 Discussion

  • LEFT OUTER JOIN으로 key인 car_id를 기준으로 모든 레코드 호출
  • WHERE로 필터링
  • DISTINCT로 중복값 제거