Mysql 日常作业(1)

作业:
Mysql 日常作业(1)_第1张图片

```
create database MyCompany;
use MyCompany;
create table if not exists EmployeeInfo(
	`Eid` int primary key auto_increment comment'员工编号',
	`Ename` varchar(20) comment '员工姓名',
	`Esex` char(2) comment '性别',
	`Ebirthday` datetime comment '生日',
	`EAddress` varchar(50) default '地址不详' comment '地址',
	`Edate` datetime comment '入职时间'
)engine=innodb default charset=utf8;

create table if not exists EScore(
	`Sid` int primary key auto_increment comment '销售编号',
	`Eid` int ,
	`Sdate` datetime comment '销售日期',
	`Smoney` decimal(18,2) comment '销售金额',
	`Sdiscount` decimal(18,1) comment '提成比例'
)engine=innodb default charset=utf8;

insert into EmployeeInfo(`Ename`,`Esex`,`Ebirthday`,`EAddress`,`Edate`)
VALUE('张无忌','男','1983-11-15','河北嵩山','2009-10-6'),
('左冷禅','男','1990-3-2','河北昆仑山','2009-7-1'),
('段延庆','男','1990-9-28','云南大理','2012-9-12'),
('孔仲尼','男','1980-4-4','山东曲阜','2003-1-1'),
('李莫愁','女','1992-8-2','燕大小吃街','2011-10-16'),
('王语嫣','女','1998-12-1','燕子坞','2014-1-2');


insert into EScore(`Eid`,`Sdate`,`Smoney`,`Sdiscount`)
value(1,'2013-11-12','64532','0.1'),
(2,'2013-11-11','46211','0.1'),
(2,'2014-1-15','7000','0.2'),
(3,'2015-3-1','83231','0.2'),
(1,'2014-12-11','8742','0.2'),
(3,'2011-10-19','23224','0.1'),
(5,'2014-4-4','50000','0.1'),
(5,'2011-11-11','90000','0.1'),
(6,'2015-2-28','30000','0.2'),
(4,'2012-12-12','99999','0.1'),
(4,'2015-1-14','84230','0.2');

# 修改 左冷禅的地址为 河北太行山
update EmployeeInfo set EAddress='河北太行山' where Ename='左冷禅';

# 修改李莫愁的地址为燕大云龙小吃城 生日为 1984-10-17
update EmployeeInfo set EAddress='燕大云龙小吃城',Ebirthday='1984-10-17' where Ename='李莫愁';

# 查询全部员工信息
select * from EmployeeInfo;

# 查询所有男员工的姓名、地址、生日并显示中文列名
select Ename as '姓名',EAddress as '地址',Ebirthday as '生日' from EmployeeInfo where Esex='男';

# 查询地址中包含山的员工信息
select * from EmployeeInfo where EAddress like '%山%';

# 查询地址中包含燕的女员工信息
select * from EmployeeInfo where EAddress like '%燕%' and Esex='女'; 

# 查询员工的姓名、地址、生日、公司名称(常量列‘大软公司’)
select Ename,EAddress,Ebirthday,'大软公司' as '公司名称' from EmployeeInfo;

# 删除孔子这名员工
delete from  EmployeeInfo where Ename='孔仲尼';

# 查询入职时间在2011到2013年之间的员工信息
select * from EmployeeInfo where `Edate` between '2011-1-1' and '2013-12-31';

# 查询有销售业绩的员工信息(in  子查询)
select * from EmployeeInfo where Eid in(select Eid from EScore where Eid!=0);

# 查询员工姓名、地址、销售日期、销售金额(表连接)
select Ename,EAddress,Sdate,Smoney from EmployeeInfo,EScore where EmployeeInfo.Eid=EScore.Eid;

-- 查询员工业绩表 显示 员工编号、销售日期、销售金额、提成比例、提成金额并显示为中文列名
SELECT
Eid '员工编号',
Sdate '销售日期',
Smoney '销售金额',
Sdiscount '提成比例',
Smoney *Sdiscount '提成金额'

FROM
EScore;
```
数据表最终结果:
Mysql 日常作业(1)_第2张图片
Mysql 日常作业(1)_第3张图片

你可能感兴趣的:(作业)