
上QQ阅读APP看书,第一时间看更新
How it works...
As you saw, based on the Connection_type column we were able to classify pre-paid and post-paid customers. Both CASE statements get executed, as can be seen in the result set. You must have noticed that the last customer has a connection type of Not Sure; this is because the Connection_type for this customer is NULL and it was not able to get processed by both the CASE statements. Therefore, it went to the default CASE statement.
This is how we can use CASE statements in Teradata SQL to cater to the function of if-else statements.
A quick review:
- The CASE statement always has the SELECT clause.
- CASE must have the following identifiers: WHEN, THEN, and END. ELSE is an optional component.
- WHERE is used as conditional statement.
- Multiple WHEN statements are allowed; an ELSE statement is used to deal with any unaddressed conditions.