CASE로 여러 그룹 만들기
이 연습 문제에서는 CASE 문을 사용해 DurationSeconds 값을 아래 구간에 따라 5개 그룹으로 분류해 보세요:
| DurationSeconds | SecondGroup |
|---|---|
| <= 120 | 1 |
| > 120 and <= 600 | 2 |
| > 600 and <= 1200 | 3 |
| > 1201 and <= 5000 | 4 |
| For all other values | 5 |
이 연습은 강의의 일부입니다
중급 SQL Server
연습 안내
위의 구간을 기준으로 DurationSeconds 열의 값을 사용해 새로운 열 SecondGroup을(를) 생성하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
-- Complete the syntax for cutting the duration into different cases
SELECT DurationSeconds,
-- Start with the 2 TSQL keywords, and after the condition a TSQL word and a value
___ ___ (DurationSeconds <= 120) ___ ___
-- The pattern repeats with the same keyword and after the condition the same word and next value
___ (DurationSeconds > 120 AND DurationSeconds <= 600) ___ ___
-- Use the same syntax here
___ (DurationSeconds > 601 AND DurationSeconds <= 1200) ___ ___
-- Use the same syntax here
___ (DurationSeconds > 1201 AND DurationSeconds <= 5000) ___ ___
-- Specify a value
ELSE ___
END AS SecondGroup
FROM Incidents