본문 바로가기
💻 하나씩 차곡차곡/프로그래머스 (SQL)

[String, Date/LEVEL3] 대여 기록이 존재하는 자동차 리스트 구하기 (MySQL/Oracle)

by 뚜루리 2023. 6. 28.
728x90
320x100

MySQL

SELECT
DISTINCT A.CAR_ID
FROM CAR_RENTAL_COMPANY_CAR A, CAR_RENTAL_COMPANY_RENTAL_HISTORY B
WHERE A.CAR_ID = B.CAR_ID
AND A.CAR_TYPE = '세단'
AND YEAR(B.START_DATE) = 2022
AND MONTH(B.START_DATE) = 10
ORDER BY A.CAR_ID DESC

 


 

Oracle

SELECT
DISTINCT A.CAR_ID
FROM CAR_RENTAL_COMPANY_CAR A, CAR_RENTAL_COMPANY_RENTAL_HISTORY B
WHERE A.CAR_ID = B.CAR_ID
AND A.CAR_TYPE = '세단'
AND TO_CHAR(B.START_DATE, 'YYYY-MM') = '2022-10'
ORDER BY A.CAR_ID DESC
728x90
320x100