
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use Enumeration Value in MySQL Expression
As we know that enumeration values are associated with index values hence if we will use enumeration values in an expression then all the calculations would be done on index numbers. 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 result from above query shows how enumeration values can be used in an expression.
Advertisements