Skip to content

Commit bce3623

Browse files
committed
[level 3] Title: 대여 기록이 존재하는 자동차 리스트 구하기, Time: 0.00 ms, Memory: 0.0 MB -BaekjoonHub
1 parent a02e9be commit bce3623

2 files changed

Lines changed: 193 additions & 0 deletions

File tree

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# [level 3] 대여 기록이 존재하는 자동차 리스트 구하기 - 157341
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/157341)
4+
5+
### 성능 요약
6+
7+
메모리: 0.0 MB, 시간: 0.00 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > String, Date
12+
13+
### 채점결과
14+
15+
Empty
16+
17+
### 제출 일자
18+
19+
2026년 01월 06일 13:59:54
20+
21+
### 문제 설명
22+
23+
<p>다음은 어느 자동차 대여 회사에서 대여 중인 자동차들의 정보를 담은 <code>CAR_RENTAL_COMPANY_CAR</code> 테이블과 자동차 대여 기록 정보를 담은 <code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블입니다. <code>CAR_RENTAL_COMPANY_CAR</code> 테이블은 아래와 같은 구조로 되어있으며, <code>CAR_ID</code>, <code>CAR_TYPE</code>, <code>DAILY_FEE</code>, <code>OPTIONS</code> 는 각각 자동차 ID, 자동차 종류, 일일 대여 요금(원), 자동차 옵션 리스트를 나타냅니다.</p>
24+
<table class="table">
25+
<thead><tr>
26+
<th>Column name</th>
27+
<th>Type</th>
28+
<th>Nullable</th>
29+
</tr>
30+
</thead>
31+
<tbody><tr>
32+
<td>CAR_ID</td>
33+
<td>INTEGER</td>
34+
<td>FALSE</td>
35+
</tr>
36+
<tr>
37+
<td>CAR_TYPE</td>
38+
<td>VARCHAR(255)</td>
39+
<td>FALSE</td>
40+
</tr>
41+
<tr>
42+
<td>DAILY_FEE</td>
43+
<td>INTEGER</td>
44+
<td>FALSE</td>
45+
</tr>
46+
<tr>
47+
<td>OPTIONS</td>
48+
<td>VARCHAR(255)</td>
49+
<td>FALSE</td>
50+
</tr>
51+
</tbody>
52+
</table>
53+
<p>자동차 종류는 '세단', 'SUV', '승합차', '트럭', '리무진' 이 있습니다. 자동차 옵션 리스트는 콤마(',')로 구분된 키워드 리스트(예: '열선시트', '스마트키', '주차감지센서')로 되어있으며, 키워드 종류는 '주차감지센서', '스마트키', '네비게이션', '통풍시트', '열선시트', '후방카메라', '가죽시트' 가 있습니다.</p>
54+
55+
<p><code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블은 아래와 같은 구조로 되어있으며, <code>HISTORY_ID</code>, <code>CAR_ID</code>, <code>START_DATE</code>, <code>END_DATE</code> 는 각각 자동차 대여 기록 ID, 자동차 ID, 대여 시작일, 대여 종료일을 나타냅니다.</p>
56+
<table class="table">
57+
<thead><tr>
58+
<th>Column name</th>
59+
<th>Type</th>
60+
<th>Nullable</th>
61+
</tr>
62+
</thead>
63+
<tbody><tr>
64+
<td>HISTORY_ID</td>
65+
<td>INTEGER</td>
66+
<td>FALSE</td>
67+
</tr>
68+
<tr>
69+
<td>CAR_ID</td>
70+
<td>INTEGER</td>
71+
<td>FALSE</td>
72+
</tr>
73+
<tr>
74+
<td>START_DATE</td>
75+
<td>DATE</td>
76+
<td>FALSE</td>
77+
</tr>
78+
<tr>
79+
<td>END_DATE</td>
80+
<td>DATE</td>
81+
<td>FALSE</td>
82+
</tr>
83+
</tbody>
84+
</table>
85+
<hr>
86+
87+
<h5>문제</h5>
88+
89+
<p><code>CAR_RENTAL_COMPANY_CAR</code> 테이블과 <code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블에서 자동차 종류가 '세단'인 자동차들 중 10월에 대여를 시작한 기록이 있는 자동차 ID 리스트를 출력하는 SQL문을 작성해주세요. 자동차 ID 리스트는 중복이 없어야 하며, 자동차 ID를 기준으로 내림차순 정렬해주세요.</p>
90+
91+
<hr>
92+
93+
<h5>예시</h5>
94+
95+
<p>예를 들어 <code>CAR_RENTAL_COMPANY_CAR</code> 테이블이 다음과 같고</p>
96+
<table class="table">
97+
<thead><tr>
98+
<th>CAR_ID</th>
99+
<th>CAR_TYPE</th>
100+
<th>DAILY_FEE</th>
101+
<th>OPTIONS</th>
102+
</tr>
103+
</thead>
104+
<tbody><tr>
105+
<td>1</td>
106+
<td>세단</td>
107+
<td>16000</td>
108+
<td>가죽시트,열선시트,후방카메라</td>
109+
</tr>
110+
<tr>
111+
<td>2</td>
112+
<td>SUV</td>
113+
<td>14000</td>
114+
<td>스마트키,네비게이션,열선시트</td>
115+
</tr>
116+
<tr>
117+
<td>3</td>
118+
<td>세단</td>
119+
<td>22000</td>
120+
<td>주차감지센서,후방카메라,가죽시트</td>
121+
</tr>
122+
<tr>
123+
<td>4</td>
124+
<td>세단</td>
125+
<td>12000</td>
126+
<td>주차감지센서</td>
127+
</tr>
128+
</tbody>
129+
</table>
130+
<p><code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블이 다음과 같다면</p>
131+
<table class="table">
132+
<thead><tr>
133+
<th>HISTORY_ID</th>
134+
<th>CAR_ID</th>
135+
<th>START_DATE</th>
136+
<th>END_DATE</th>
137+
</tr>
138+
</thead>
139+
<tbody><tr>
140+
<td>1</td>
141+
<td>4</td>
142+
<td>2022-09-27</td>
143+
<td>2022-09-27</td>
144+
</tr>
145+
<tr>
146+
<td>2</td>
147+
<td>3</td>
148+
<td>2022-10-03</td>
149+
<td>2022-10-04</td>
150+
</tr>
151+
<tr>
152+
<td>3</td>
153+
<td>2</td>
154+
<td>2022-10-05</td>
155+
<td>2022-10-05</td>
156+
</tr>
157+
<tr>
158+
<td>4</td>
159+
<td>1</td>
160+
<td>2022-10-11</td>
161+
<td>2022-10-14</td>
162+
</tr>
163+
<tr>
164+
<td>5</td>
165+
<td>3</td>
166+
<td>2022-10-13</td>
167+
<td>2022-10-15</td>
168+
</tr>
169+
</tbody>
170+
</table>
171+
<p>10월에 대여를 시작한 기록이 있는 '세단' 종류의 자동차는 자동차 ID가 1, 3 인 자동차이고, 자동차 ID를 기준으로 내림차순 정렬하면 다음과 같이 나와야 합니다.</p>
172+
<table class="table">
173+
<thead><tr>
174+
<th>CAR_ID</th>
175+
</tr>
176+
</thead>
177+
<tbody><tr>
178+
<td>3</td>
179+
</tr>
180+
<tr>
181+
<td>1</td>
182+
</tr>
183+
</tbody>
184+
</table>
185+
186+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT DISTINCT A.CAR_ID AS CAR_ID
2+
FROM CAR_RENTAL_COMPANY_CAR A
3+
JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY B
4+
ON A.CAR_ID = B.CAR_ID
5+
WHERE MONTH(B.START_DATE) = 10
6+
AND A.CAR_TYPE = '세단'
7+
ORDER BY A.CAR_ID DESC

0 commit comments

Comments
 (0)