ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mysql基础练习题

2022-08-15 19:31:35  阅读:268  来源: 互联网

标签:练习题 salary 08 基础 点击 emp mysql where select


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;

update emp set salary=20000 where time>20101231;
点击查看

4、修改emp表中年龄大于30岁,并且入职时间在2010年后的员工工资为22000;

update emp set salary=22000 where time>20101231 and age>30;
点击查看

5、修改emp表中姓名为'HMM',性别为'女'的员工年龄为18;

update emp set age=18 where name='HMM' and sex='女';
点击查看

6、删除emp表中工资大于20000的员工信息;

delete from emp where salary>20000;
点击查看

7、删除emp表中工资小于8000,且入职时间晚于2020-01-01的员工信息;

delete from emp where salary<8000 and time>2020-01-01;
点击查看

8、查询emp表中的所有员工姓名,年龄以及工资信息;

select name,age,salary from emp;
点击查看

9、查询emp表中年龄大于28岁的所有员工相关信息;

select * from emp where age>28;
点击查看

10、查询emp表中年龄小于25岁,性别为女的员工的姓名,履历以及入职时间等信息;

select name,resume,time from emp where age<25 and sex='女';
点击查看

11、查询emp表中年龄大于20岁,或是性别为女的所有员工的姓名,年龄,工资及入职时间等信息;

select name,age,salary,time from emp where age>20 or sex='女';
点击查看

12、给emp表中入职时间大于1年的员工工资加1000,datediff(now(),time) /timestampdiff(year,time,now())  计算时间差方法

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:查询出部门中张姓员工的相关信息;

select * from emp where name like '张_';
点击查看

#4:查询出部门中年龄在18岁到25岁之间的所有员工相关信息

select * from emp where age between 18 and 25;
点击查看

# 5:查询出部门中工资高于20000的员工的相关信息;

select * from emp where salary >20000;
点击查看

# 6:查询出部门中工资高于15000并且年龄小于25并且性别的女的所有员工相关信息;

select * from emp where salary>15000 and age<25 and sex='女';
点击查看

# 7:查询出部门中工资不大于20000的所有员工相关信息;

select * from emp where salary<2000;
点击查看

# 8:查询出部门中员工名字中包含“风”字的员工信息;

select * from emp where name like '%风%';
点击查看

# 9:删除部门中工资大于20000且年龄大于30岁且性别不为女的员工相关信息;

delete from emp where salary>20000 and age>30 and sex!='女';
点击查看

# 10:为部门中入职时间在2010年之前的所有员工增加工资2000;

update emp set salary=salary+2000 where year(time)<2010;
点击查看

# 11:查询出部门名为“软件测试部”中所有员工的一个月工资开销总和;

select sum(salary) from emp where dep='软件测试部';
点击查看

# 12:查询出部门为“软件测试部”中一共有多少员工;

select count(*) from emp where dep='软件测试部';
点击查看

# 13:查询出部门为“软件测试部”的最高工资;

select max(salary) from emp where dep='软件测试部';
点击查看

# 14:查询出部门为“软件测试部”的平均工资;

select avg(salary) from emp where dep='软件测试部';
点击查看

# 15:查询出部门为“软件测试部”的员工相关信息,并根据工资从低到高进行排序;

select * from emp where dep='软件测试部' order by salary;
点击查看

 


 

标签:练习题,salary,08,基础,点击,emp,mysql,where,select
来源: https://www.cnblogs.com/hqh2021/p/16581271.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有