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

allnight5·2023년 5월 24일
0

프로그래머스SQL

목록 보기
13/19
-- 코드를 입력하세요
SELECT CRCC.CAR_ID FROM CAR_RENTAL_COMPANY_CAR AS CRCC
JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY AS CRCRH
ON CRCRH.CAR_ID = CRCC.CAR_ID
WHERE CRCC.CAR_TYPE = '세단' AND CRCRH.START_DATE LIKE '%-10-%'
GROUP BY CRCRH.CAR_ID
ORDER BY CRCC.CAR_ID DESC

다른방식 서브쿼리 1

-- 코드를 입력하세요
SELECT CAR_ID 
FROM CAR_RENTAL_COMPANY_CAR
WHERE CAR_TYPE = '세단' 
AND 
CAR_ID IN 
(SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY 
WHERE START_DATE LIKE '%-10-%'
)
ORDER BY CAR_ID DESC

다른방식 서브쿼리 2

SELECT CAR_ID
FROM (
  SELECT CRCC.CAR_ID
  FROM CAR_RENTAL_COMPANY_CAR AS CRCC
  JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY AS CRCRH
  ON CRCRH.CAR_ID = CRCC.CAR_ID
  WHERE CRCC.CAR_TYPE = '세단' AND CRCRH.START_DATE LIKE '%-10-%'
  GROUP BY CRCRH.CAR_ID
) AS Subquery
ORDER BY CAR_ID DESC
profile
공부기록하기

0개의 댓글