#通过四则运算查询
SELECT name, salary*12 FROM employee; SELECT name, salary*12 AS Annual_salary FROM employee; SELECT name, salary*12 Annual_salary FROM employee;
查看年薪salary*12
mysql> select name,salary*12 from employee; +------------+-------------+ | name | salary*12 | +------------+-------------+ | alex | 12000003.72 | | yuanhao | 42000.00 | | liwenzhou | 25200.00 | | jingliyang | 108000.00 | | jinxin | 360000.00 | | 成龙 | 120000.00 | | 歪歪 | 36001.56 | | 丫丫 | 24004.20 | | 丁丁 | 12004.44 | | 星星 | 36003.48 | | 格格 | 48003.96 | | 张野 | 120001.56 | | 程咬金 | 240000.00 | | 程咬银 | 228000.00 | | 程咬铜 | 216000.00 | | 程咬铁 | 204000.00 | +------------+-------------+ 16 rows in set (0.10 sec)
查出来的结果 这是一张虚拟表
因为查出来结果 标注红色的 salary*12 不太直观 利用另外一种方式查表
as 给字段起别名
select 字段 as 别名 from 表名
mysql> select name,salary*12 as Annual_salary from employee; +------------+---------------+ | name | Annual_salary | +------------+---------------+ | alex | 12000003.72 | | yuanhao | 42000.00 | | liwenzhou | 25200.00 | | jingliyang | 108000.00 | | jinxin | 360000.00 | | 成龙 | 120000.00 | | 歪歪 | 36001.56 | | 丫丫 | 24004.20 | | 丁丁 | 12004.44 | | 星星 | 36003.48 | | 格格 | 48003.96 | | 张野 | 120001.56 | | 程咬金 | 240000.00 | | 程咬银 | 228000.00 | | 程咬铜 | 216000.00 | | 程咬铁 | 204000.00 | +------------+---------------+ 16 rows in set (0.10 sec)
不加as也可以 默认后面就是别名
mysql> select name,salary*12 Annual_salary from employee; +------------+---------------+ | name | Annual_salary | +------------+---------------+ | alex | 12000003.72 | | yuanhao | 42000.00 | | liwenzhou | 25200.00 | | jingliyang | 108000.00 | | jinxin | 360000.00 | | 成龙 | 120000.00 | | 歪歪 | 36001.56 | | 丫丫 | 24004.20 | | 丁丁 | 12004.44 | | 星星 | 36003.48 | | 格格 | 48003.96 | | 张野 | 120001.56 | | 程咬金 | 240000.00 | | 程咬银 | 228000.00 | | 程咬铜 | 216000.00 | | 程咬铁 | 204000.00 | +------------+---------------+ 16 rows in set (0.00 sec)
原文地址:https://www.cnblogs.com/mingerlcm/p/9874233.html
时间: 2024-10-11 02:35:19