SQL ระดับกลางด้วย AI
Jasmin Ludolf
Senior Data Science Content Developer
|duration|
|--------|
|123 |
|110 |
|151 |
...
จัดหมวดหมู่เป็น "Short", "Standard", "Epic"
duration > 90: ใช่หรือไม่
ใช้ conditional logic

Prompt: จัดหมวดหมู่ภาพยนตร์เป็น Short หากความยาวน้อยกว่า 90 นาที, Standard หากน้อยกว่า 150 นาที และ Epic ในกรณีอื่น
SELECT
id,
title,
duration,
CASE
WHEN duration < 90 THEN 'Short'
WHEN duration < 150 THEN 'Standard'
ELSE 'Epic'
END AS film_category
FROM films;
Prompt: จัดหมวดหมู่ภาพยนตร์เป็น Short หากความยาวน้อยกว่า 90 นาที, Standard หากน้อยกว่า 150 นาที และ Epic ในกรณีอื่น
SELECT
id,
title,
duration,
CASE
WHEN duration < 150 THEN 'Standard'
WHEN duration < 90 THEN 'Short'
ELSE 'Epic'
END AS film_category
FROM films;
$$
Prompt: จัดหมวดหมู่ภาพยนตร์เป็น Short หากน้อยกว่า 90 นาที, Standard หากอยู่ระหว่าง 90 ถึง 149 นาที, Epic หาก 150 นาทีขึ้นไป และ 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 |
...
Prompt: ลบแถวที่ duration เป็น NULL ออก
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 ระดับกลางด้วย AI