如何在MySQL计算中使用别名?
让我们首先创建表。创建表的查询如下-
mysql> create table AliasDemo−> (
−> Id int
−> );
借助insert命令将一些记录插入表中。以下是插入记录的查询-
mysql> insert into AliasDemo values(20);mysql> insert into AliasDemo values(30);
mysql> insert into AliasDemo values(40);
现在您可以在select语句的帮助下显示所有记录-
mysql> select *from AliasDemo;
以下是输出-
+------+| Id |
+------+
| 20 |
| 30 |
| 40 |
+------+
3 rows in set (0.00 sec)
这是在计算中设置别名的查询-
mysql> select Id,100 as MyNumber ,(select MyNumber)*Id as MultiplyWith100 from AliasDemo;
以下是输出-
+------+----------+-----------------+| Id | MyNumber | MultiplyWith100 |
+------+----------+-----------------+
| 20 | 100 | 2000 |
| 30 | 100 | 3000 |
| 40 | 100 | 4000 |
+------+----------+-----------------+
3 rows in set (0.00 sec)
您可以一次执行。查询如下-
mysql> select 100 as MyNumber,(select MyNumber)*10 as MultiplyWith100;
以下是输出-
+----------+-----------------+| MyNumber | MultiplyWith100 |
+----------+-----------------+
| 100 | 1000 |
+----------+-----------------+
1 row in set (0.00 sec)
以上是 如何在MySQL计算中使用别名? 的全部内容, 来源链接: utcz.com/z/343578.html