众所周知,枚举值与索引值相关联,因此,如果我们在表达式中使用枚举值,则所有计算都将基于索引号进行。以下示例将对其进行澄清-
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)
以上查询的结果显示了如何在表达式中使用枚举值。