SQL średnio zaawansowany z pomocą AI
Jasmin Ludolf
Senior Data Science Content Developer
|duration|
|--------|
|123 |
|110 |
|151 |
...
Kategoryzacja jako „Short", „Standard", „Epic"
duration > 90: tak lub nie
Zastosowanie logiki warunkowej

Polecenie: Kategoryzuj filmy jako Short, jeśli czas trwania wynosi poniżej 90 minut, Standard – poniżej 150, w przeciwnym razie Epic
SELECT
id,
title,
duration,
CASE
WHEN duration < 90 THEN 'Short'
WHEN duration < 150 THEN 'Standard'
ELSE 'Epic'
END AS film_category
FROM films;
Polecenie: Kategoryzuj filmy jako Short, jeśli czas trwania wynosi poniżej 90 minut, Standard – poniżej 150, w przeciwnym razie Epic
SELECT
id,
title,
duration,
CASE
WHEN duration < 150 THEN 'Standard'
WHEN duration < 90 THEN 'Short'
ELSE 'Epic'
END AS film_category
FROM films;
$$
Polecenie: Kategoryzuj filmy jako Short (poniżej 90 min), Standard (90–149 min), Epic (150 min lub więcej), w pozostałych przypadkach 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 |
...
Polecenie: Usuń wiersze z NULL w kolumnie 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;
$$
$$
$$

SQL średnio zaawansowany z pomocą AI