문제 설명은 문제 아래의 링크를 참고.
대여 기록이 존재하는 자동차 리스트 구하기
https://school.programmers.co.kr/learn/courses/30/lessons/157341
풀이
SELECT DISTINCT C.CAR_ID
FROM CAR_RENTAL_COMPANY_CAR C
JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY H
ON C.CAR_ID = H.CAR_ID
WHERE C.CAR_TYPE = "세단" AND H.START_DATE LIKE "2022-10%"
ORDER BY C.CAR_ID DESC;
자동차 대여 기록에서 대여중 / 대여 가능 여부 구분하기
https://school.programmers.co.kr/learn/courses/30/lessons/157340
풀이
SELECT CAR_ID,
MAX(CASE
WHEN "2022-10-16" BETWEEN START_DATE AND END_DATE
THEN "대여중"
ELSE "대여 가능"
END) AS "AVAILABILITY"
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
GROUP BY CAR_ID
ORDER BY CAR_ID DESC;
보호소에서 중성화한 동물
https://school.programmers.co.kr/learn/courses/30/lessons/59045
풀이
SELECT I.ANIMAL_ID, I.ANIMAL_TYPE, I.NAME
FROM ANIMAL_INS I
JOIN ANIMAL_OUTS O
ON I.ANIMAL_ID = O.ANIMAL_ID
WHERE I.SEX_UPON_INTAKE LIKE "Intact%" AND
(O.SEX_UPON_OUTCOME LIKE "Neutered%" OR O.SEX_UPON_OUTCOME LIKE "Spayed%")
ORDER BY I.ANIMAL_ID;
식품분류별 가장 비싼 식품의 정보 조회하기
https://school.programmers.co.kr/learn/courses/30/lessons/131116
풀이
SELECT CATEGORY, PRICE AS "MAX_PRICE", PRODUCT_NAME
FROM FOOD_PRODUCT
WHERE PRICE IN (SELECT MAX(PRICE)
FROM FOOD_PRODUCT
GROUP BY CATEGORY
HAVING CATEGORY IN ('과자','국','김치','식용유'))
AND CATEGORY IN ('과자','국','김치','식용유')
ORDER BY PRICE DESC;