MySQL 如何使用枚举值在表达式中
我们知道,枚举值与索引值相关联,因此,如果将枚举值用于表达式中,所有的计算都将在索引数字上进行。以下示例将说明此问题 −
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)
以上查询的结果显示了如何在表达式中使用枚举值。
阅读更多:MySQL 教程