在 MySQL 查询中将某一列除以一个值来获取员工的月薪?
我们首先创建一个表格 -
mysql> create table DemoTable1957 ( EmployeeId int, EmployeeName varchar(20), EmployeeSalary int ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1957 values(1,'Chris',240000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(2,'Bob',120000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(3,'David',180000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(4,'Mike',650000); Query OK, 1 row affected (0.00 sec)
使用 select 语句从表中显示所有记录 -
mysql> select * from DemoTable1957;
这将产生以下输出 -
+------------+--------------+----------------+ | EmployeeId | EmployeeName | EmployeeSalary | +------------+--------------+----------------+ | 1 | Chris | 240000 | | 2 | Bob | 120000 | | 3 | David | 180000 | | 4 | Mike | 650000 | +------------+--------------+----------------+ 4 rows in set (0.00 sec)
以下是获取员工月薪的查询
mysql> select EmployeeName,EmployeeSalary/12 As MonthlySalary from DemoTable1957;
这将产生以下输出 -
+--------------+---------------+ | EmployeeName | MonthlySalary | +--------------+---------------+ | Chris | 20000.0000 | | Bob | 10000.0000 | | David | 15000.0000 | | Mike | 54166.6667 | +--------------+---------------+ 4 rows in set (0.00 sec)
广告