Home > Database > Mysql Tutorial > How are enumeration values ​​in MySQL used in expressions?

How are enumeration values ​​in MySQL used in expressions?

王林
Release: 2023-08-30 19:49:08
forward
600 people have browsed it

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template