让我们首先创建一个表-
mysql> create table DemoTable1957 ( EmployeeId int, EmployeeName varchar(20), EmployeeSalary int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1957 values(1,'Chris',240000); mysql> insert into DemoTable1957 values(2,'Bob',120000); mysql> insert into DemoTable1957 values(3,'David',180000); mysql> insert into DemoTable1957 values(4,'Mike',650000);
使用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)