Make more complete value with case statement : CASE « Function « SQL / MySQL






Make more complete value with case statement

      
mysql>
mysql> CREATE   TABLE TEAMS
    ->         (TEAMNO         INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          DIVISION       CHAR(6)      NOT NULL,
    ->          PRIMARY KEY    (TEAMNO)             );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO TEAMS VALUES (1,  6, 'first');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO TEAMS VALUES (2, 27, 'second');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> SELECT   TEAMNO,
    ->          CASE DIVISION
    ->             WHEN 'first' then 'first division'
    ->             WHEN 'second' THEN 'second division'
    ->             ELSE 'unknown' END AS DIVISION
    -> FROM     TEAMS;
+--------+-----------------+
| TEAMNO | DIVISION        |
+--------+-----------------+
|      1 | first division  |
|      2 | second division |
+--------+-----------------+
2 rows in set (0.00 sec)

mysql>
mysql> drop table teams;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
  








Related examples in the same category

1.CASE() Function
2.The next version of the CASE() function
3.CASE Branching
4.CASE is a variant of IF that is useful when all the branch decisions depend on the value of a single expression.
5.Using case in select statement
6.Use both case expressions shown previously in a SELECT statement.
7.Using the comparison value form of CASE...WHEN
8.Using CASE...WHEN for evaluating conditions
9.Variants of CASE.WHEN with no ELSE clause
10.Use a CASE...WHEN function to indicate that the different categories have different sales trends
11.Case without else clause
12.Nested case statement
13.Case with comparison
14.Case when with and operator
15.Provide more meaningful value with case clause
16.Using case statement to check a range
17.Use case else to check the exceptions
18.Using case with comparison
19.Case clause and aggregate function
20.If ELSE is omitted, the null value is returned.