mysql基础练习题
test1
1、创建emp表,设计字段为id,name,age,sex, salary(工资),resume(履历),time(入职时间)。
2、往表中添加数据如下:
insert into emp(name,age,sex,salary,resume,time) values ('a1',18,'女',8888.88,'tester a1','2018-08-08'),
('a2',18,'女',8888.88,'tester a2','2018-08-08'),
('a3',18,'女',8888.88,'tester a3','2018-08-08'),
('a4',18,'女',8888.88,'tester a4','2018-08-08'),
('a5',18,'女',8888.88,'tester a5','2018-08-08');
3、修改入职时间在2010年后的员工工资为20000;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
update emp set salary=20000 where time>20101231;点击查看
4、修改emp表中年龄大于30岁,并且入职时间在2010年后的员工工资为22000;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
update emp set salary=22000 where time>20101231 and age>30;点击查看
5、修改emp表中姓名为'HMM',性别为'女'的员工年龄为18;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
update emp set age=18 where name='HMM' and sex='女';点击查看
6、删除emp表中工资大于20000的员工信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
delete from emp where salary>20000;点击查看
7、删除emp表中工资小于8000,且入职时间晚于2020-01-01的员工信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
delete from emp where salary<8000 and time>2020-01-01;点击查看
8、查询emp表中的所有员工姓名,年龄以及工资信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select name,age,salary from emp;点击查看
9、查询emp表中年龄大于28岁的所有员工相关信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where age>28;点击查看
10、查询emp表中年龄小于25岁,性别为女的员工的姓名,履历以及入职时间等信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select name,resume,time from emp where age<25 and sex='女';点击查看
11、查询emp表中年龄大于20岁,或是性别为女的所有员工的姓名,年龄,工资及入职时间等信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select name,age,salary,time from emp where age>20 or sex='女';点击查看
12、给emp表中入职时间大于1年的员工工资加1000,datediff(now(),time) /timestampdiff(year,time,now()) 计算时间差方法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
update emp set salary = salary + 1000 where datediff(now(),time) > 365; update emp set salary = salary + 1000 where timestampdiff(year,time,now()) > 0;点击查看
test2
#1:创建表emp表,设计字段为id,name,age,sex, salary(工资),dep(部门),time(入职时间)。#2:往表中添加如下数据:
insert into emp values (1,'a1',18,'女',8888.88,'tester a1','2018-08-08'),
(2,'a2',18,'女',8888.88,'tester a2','2018-08-08'),
(3,'a3',18,'女',8888.88,'tester a3','2018-08-08'),
(4,'a4',18,'女',8888.88,'tester a4','2018-08-08'),
(5,'a5',18,'女',8888.88,'tester a5','2018-08-08');
#3:查询出部门中张姓员工的相关信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where name like '张_';点击查看
#4:查询出部门中年龄在18岁到25岁之间的所有员工相关信息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where age between 18 and 25;点击查看
# 5:查询出部门中工资高于20000的员工的相关信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where salary >20000;点击查看
# 6:查询出部门中工资高于15000并且年龄小于25并且性别的女的所有员工相关信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where salary>15000 and age<25 and sex='女';点击查看
# 7:查询出部门中工资不大于20000的所有员工相关信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where salary<2000;点击查看
# 8:查询出部门中员工名字中包含“风”字的员工信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where name like '%风%';点击查看
# 9:删除部门中工资大于20000且年龄大于30岁且性别不为女的员工相关信息;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
delete from emp where salary>20000 and age>30 and sex!='女';点击查看
# 10:为部门中入职时间在2010年之前的所有员工增加工资2000;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
update emp set salary=salary+2000 where year(time)<2010;点击查看
# 11:查询出部门名为“软件测试部”中所有员工的一个月工资开销总和;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select sum(salary) from emp where dep='软件测试部';点击查看
# 12:查询出部门为“软件测试部”中一共有多少员工;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select count(*) from emp where dep='软件测试部';点击查看
# 13:查询出部门为“软件测试部”的最高工资;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select max(salary) from emp where dep='软件测试部';点击查看
# 14:查询出部门为“软件测试部”的平均工资;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select avg(salary) from emp where dep='软件测试部';点击查看
# 15:查询出部门为“软件测试部”的员工相关信息,并根据工资从低到高进行排序;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
select * from emp where dep='软件测试部' order by salary;点击查看
标签:练习题,salary,08,基础,点击,emp,mysql,where,select From: https://www.cnblogs.com/hqh2021/p/16581271.html