शुरू करेंमुफ़्त में शुरू करें

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

पाठ्यक्रम देखें

अभ्यास निर्देश

एक नया कॉलम 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
कोड संपादित करें और चलाएँ