Home  >  Article  >  Database  >  How to use SELECT to evaluate an expression in MySQL without referencing any table?

How to use SELECT to evaluate an expression in MySQL without referencing any table?

WBOY
WBOYforward
2023-09-04 21:21:03874browse

如何在不引用任何表的情况下使用 SELECT 来计算 MySQL 中的表达式?

With the help of the following MySQL statement, we can use SELECT to evaluate the expression -

SELECT expression;

The above statement does not refer to any table. Here are some examples -

mysql> Select 10 DIV 5;
+----------+
| 10 DIV 5 |
+----------+
|        2 |
+----------+
1 row in set (0.06 sec)

mysql> Select 10*5;
+------+
| 10*5 |
+------+
|   50 |
+------+
1 row in set (0.00 sec)

mysql> Set @var1 = 100, @var2 = 200;
Query OK, 0 rows affected (0.00 sec)

mysql> Select @Var1+@Var2;
+-------------+
| @Var1+@Var2 |
+-------------+
|         300 |
+-------------+
1 row in set (0.00 sec)

The above is the detailed content of How to use SELECT to evaluate an expression in MySQL without referencing any table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete