AI로 배우는 중급 SQL 쿼리
Jasmin Ludolf
Senior Data Science Content Developer
|duration|
|--------|
|123 |
|110 |
|151 |
...
"Short", "Standard", "Epic"으로 분류
duration > 90: 예/아니오
조건부 로직 사용

프롬프트: duration이 90분 미만이면 Short, 150 미만이면 Standard, 그 외는 Epic으로 분류
SELECT
id,
title,
duration,
CASE
WHEN duration < 90 THEN 'Short'
WHEN duration < 150 THEN 'Standard'
ELSE 'Epic'
END AS film_category
FROM films;
프롬프트: duration이 90분 미만이면 Short, 150 미만이면 Standard, 그 외는 Epic으로 분류
SELECT
id,
title,
duration,
CASE
WHEN duration < 150 THEN 'Standard'
WHEN duration < 90 THEN 'Short'
ELSE 'Epic'
END AS film_category
FROM films;
$$
프롬프트: 90분 미만은 Short, 90~149분은 Standard, 150분 이상은 Epic, 그 외는 unknown으로 분류
SELECT
id,
title,
duration,
CASE
WHEN duration < 90 THEN 'Short'
WHEN duration BETWEEN 90 AND 149 THEN 'Standard'
WHEN duration >= 150 THEN 'Epic'
ELSE 'Unknown'
END AS category
FROM films;
$$
|id|title |duration|category|
|--|------------------------------------------------|--------|--------|
|1 |Intolerance: Love's Struggle Throughout the Ages|123 |Standard|
|2 |Over the Hill to the Poorhouse |110 |Standard|
|3 |The Big Parade |151 |Epic |
|4 |Metropolis |145 |Standard|
...
|id |title |duration|category|
|----|-------|--------|--------|
|4396|Destiny| |Unknown |
...
프롬프트: NULL duration 제거
SELECT id, title, duration, CASE WHEN duration < 90 THEN 'Short' WHEN duration BETWEEN 90 AND 149 THEN 'Standard' WHEN duration >= 150 THEN 'Epic' ELSE 'Unknown' END AS category FROM filmsWHERE duration IS NOT NULL;
$$
$$
$$

AI로 배우는 중급 SQL 쿼리