[Programmers_SQL] 13. 자동차 종류 별 특정 옵션이 포함된 자동차 수 구하기

문정준's avatar
Mar 06, 2025
[Programmers_SQL] 13. 자동차 종류 별 특정 옵션이 포함된 자동차 수 구하기
 
💡
프로그래머스 GROUP BY 1. 자동차 종류 별 특정 옵션이 포함된 자동차 수 구하기

1. 문제 설명

notion image
 

2. 문제

notion image

3. 예시

notion image
 

4. 문제 풀이

SELECT car_type, count(car_type) cars from CAR_RENTAL_COMPANY_CAR where options like '%통풍시트%' or options like '%열선시트%' or options like '%가죽시트%' group by car_type order by car_type;
  • 1 Line : 차종, 차의 대수를 출력
    • 차의 대수는 ‘CARS’ 라는 별칭 부여
    • SELECT car_type, count(car_type) cars
  • 2 Line : CAR_RENTAL_COMPANY_CAR 데이터에서 출력
    • from CAR_RENTAL_COMPANY_CAR
  • 3 Line : ‘통풍시트’, ‘열선시트’, ‘가죽시트’ 중 하나 이상의 옵션이 포함된 자동차를 출력
    • options에서 하나의 텍스트로 연결되어 있기 때문에 like 사용
    • where options like '%통풍시트%' or options like '%열선시트%' or options like '%가죽시트%'
  • 4 Line : 차종 별로 정렬
    • group by car_type
  • 5 Line : car_type을 기준으로 오름차순 정렬
    • order by car_type;

5. 결과 확인

notion image
notion image
 
Share article

sxias