Skip to content

Commit dc46c51

Browse files
committed
[level 3] Title: 자동차 대여 기록에서 대여중 / 대여 가능 여부 구분하기, Time: 0.00 ms, Memory: 0.0 MB -BaekjoonHub
1 parent be5366a commit dc46c51

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# [level 3] 자동차 대여 기록에서 대여중 / 대여 가능 여부 구분하기 - 157340
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/157340)
4+
5+
### 성능 요약
6+
7+
메모리: 0.0 MB, 시간: 0.00 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > GROUP BY
12+
13+
### 채점결과
14+
15+
Empty
16+
17+
### 제출 일자
18+
19+
2025년 11월 05일 09:50:35
20+
21+
### 문제 설명
22+
23+
<p>다음은 어느 자동차 대여 회사의 자동차 대여 기록 정보를 담은 <code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블입니다. <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>
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>HISTORY_ID</td>
33+
<td>INTEGER</td>
34+
<td>FALSE</td>
35+
</tr>
36+
<tr>
37+
<td>CAR_ID</td>
38+
<td>INTEGER</td>
39+
<td>FALSE</td>
40+
</tr>
41+
<tr>
42+
<td>START_DATE</td>
43+
<td>DATE</td>
44+
<td>FALSE</td>
45+
</tr>
46+
<tr>
47+
<td>END_DATE</td>
48+
<td>DATE</td>
49+
<td>FALSE</td>
50+
</tr>
51+
</tbody>
52+
</table>
53+
<hr>
54+
55+
<h5>문제</h5>
56+
57+
<p><code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블에서 2022년 10월 16일에 대여 중인 자동차인 경우 '대여중' 이라고 표시하고, 대여 중이지 않은 자동차인 경우 '대여 가능'을 표시하는 컬럼(컬럼명: <code>AVAILABILITY</code>)을 추가하여 자동차 ID와 <code>AVAILABILITY</code> 리스트를 출력하는 SQL문을 작성해주세요. 이때 반납 날짜가 2022년 10월 16일인 경우에도 '대여중'으로 표시해주시고 결과는 자동차 ID를 기준으로 내림차순 정렬해주세요.</p>
58+
59+
<hr>
60+
61+
<h5>예시</h5>
62+
63+
<p>예를 들어 <code>CAR_RENTAL_COMPANY_RENTAL_HISTORY</code> 테이블이 다음과 같다면</p>
64+
<table class="table">
65+
<thead><tr>
66+
<th>HISTORY_ID</th>
67+
<th>CAR_ID</th>
68+
<th>START_DATE</th>
69+
<th>END_DATE</th>
70+
</tr>
71+
</thead>
72+
<tbody><tr>
73+
<td>1</td>
74+
<td>4</td>
75+
<td>2022-09-27</td>
76+
<td>2022-09-27</td>
77+
</tr>
78+
<tr>
79+
<td>2</td>
80+
<td>3</td>
81+
<td>2022-10-03</td>
82+
<td>2022-10-04</td>
83+
</tr>
84+
<tr>
85+
<td>3</td>
86+
<td>2</td>
87+
<td>2022-10-05</td>
88+
<td>2022-10-05</td>
89+
</tr>
90+
<tr>
91+
<td>4</td>
92+
<td>1</td>
93+
<td>2022-10-11</td>
94+
<td>2022-10-16</td>
95+
</tr>
96+
<tr>
97+
<td>5</td>
98+
<td>3</td>
99+
<td>2022-10-13</td>
100+
<td>2022-10-15</td>
101+
</tr>
102+
<tr>
103+
<td>6</td>
104+
<td>2</td>
105+
<td>2022-10-15</td>
106+
<td>2022-10-17</td>
107+
</tr>
108+
</tbody>
109+
</table>
110+
<p>2022년 10월 16일에 대여 중인 자동차는 자동차 ID가 1, 2인 자동차이고, 대여 가능한 자동차는 자동차 ID가 3, 4이므로, '대여중' 또는 '대여 가능' 을 표시하는 컬럼을 추가하고, 자동차 ID를 기준으로 내림차순 정렬하면 다음과 같이 나와야 합니다.</p>
111+
<table class="table">
112+
<thead><tr>
113+
<th>CAR_ID</th>
114+
<th>AVAILABILITY</th>
115+
</tr>
116+
</thead>
117+
<tbody><tr>
118+
<td>4</td>
119+
<td>대여 가능</td>
120+
</tr>
121+
<tr>
122+
<td>3</td>
123+
<td>대여 가능</td>
124+
</tr>
125+
<tr>
126+
<td>2</td>
127+
<td>대여중</td>
128+
</tr>
129+
<tr>
130+
<td>1</td>
131+
<td>대여중</td>
132+
</tr>
133+
</tbody>
134+
</table>
135+
136+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT
2+
CAR_ID,
3+
CASE
4+
WHEN SUM(CASE WHEN '2022-10-16' BETWEEN START_DATE AND END_DATE THEN 1 ELSE 0 END) > 0
5+
THEN '대여중'
6+
ELSE '대여 가능'
7+
END AS AVAILABILITY
8+
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
9+
GROUP BY CAR_ID
10+
ORDER BY CAR_ID DESC;

0 commit comments

Comments
 (0)