Home >Database >Mysql Tutorial >How are enumeration values in MySQL used in expressions?
As we all know that enumeration values are associated with index values, so if we use enumeration values in expressions, then all calculations will be done on the index number. The following example will clarify it -
mysql> Select * from Result; +-----+--------+-------+ | Id | Name | Grade | +-----+--------+-------+ | 100 | Gaurav | GOOD | | 101 | Rahul | POOR | | 102 | Rahul | NULL | | 103 | Mohan | | +-----+--------+-------+ 4 rows in set (0.00 sec) mysql> Select SUM(Grade) from result; +------------+ | SUM(Grade) | +------------+ | 3 | +------------+ 1 row in set (0.00 sec) mysql> Select AVG(Grade) from result; +------------+ | AVG(Grade) | +------------+ | 1 | +------------+ 1 row in set (0.00 sec) mysql> Select Grade+0 from result; +---------+ | Grade+0 | +---------+ | 2 | | 1 | | NULL | | 0 | +---------+ 4 rows in set (0.00 sec) mysql> Select Grade-1 from result; +---------+ | Grade-1 | +---------+ | 1 | | 0 | | NULL | | -1 | +---------+ 4 rows in set (0.00 sec)
The results of the above query show how to use enumeration values in expressions.
The above is the detailed content of How are enumeration values in MySQL used in expressions?. For more information, please follow other related articles on the PHP Chinese website!