Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Custom classifications of business objects
Custom grouping of business objects
Custom counting of business objects
Summary
15. Summary

Instruction

You did well! All right, it's time to wrap things up. First, let's summarize what we've covered in this part:

  1. A CASE WHEN statement checks for one or more conditions and returns a value when it finds the first matching condition. If there is no ELSE clause and no matching conditions, CASE WHEN returns NULL.
    CASE
      WHEN condition1 THEN result1
      WHEN condition2 THEN result2
      ...
      ELSE result
    END
    
  2. To add a new column, and thus a custom classification of business products, you can use CASE WHEN in the SELECT clause:
    SELECT 
      CASE
        WHEN ... THEN ...
      END AS SampleColumn
    FROM Table;
    
  3. You can use CASE WHEN in a GROUP BY clause to create your own grouping. The same CASE WHEN clause must also appear in the SELECT clause:
    SELECT 
      CASE
        WHEN ... THEN ...
      END AS SampleColumn,
      COUNT(*) AS SampleCount
    FROM Table
      ...
    GROUP BY
      CASE WHEN ... THEN ...
      END;
    
  4. You can create a custom count of business objects using CASE WHEN inside a COUNT() or SUM() function:
    SELECT 
      COUNT(CASE
        WHEN ... THEN ColumnName
      END) AS CountColumn
    FROM Table;
    
    SELECT 
      SUM(CASE
        WHEN ... THEN 1
      END) AS CountColumn
    FROM Table;
    

How about a short quiz now?

Exercise

Click Next exercise to continue.