Создание нескольких групп с помощью CASE
В этом упражнении вы напишете оператор CASE, чтобы разбить значения столбца DurationSeconds на 5 групп по следующим диапазонам:
| DurationSeconds | SecondGroup |
|---|---|
| <= 120 | 1 |
| > 120 и <= 600 | 2 |
| > 600 и <= 1200 | 3 |
| > 1201 и <= 5000 | 4 |
| Все остальные значения | 5 |
Это упражнение является частью курса
Средний уровень SQL Server
Инструкции к упражнению
Создайте новый столбец SecondGroup, который принимает значения из столбца DurationSeconds в соответствии с указанными выше диапазонами.
Интерактивное практическое упражнение
Попробуйте выполнить это упражнение, дополнив этот пример кода.
-- 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