# 1)    创建student表
create table student(
sid int primary key auto_increment,
sname varchar(20) not null,
age int
);
# 2)    向该表插入一条数据:
#      编号:1     姓名:张三   年龄:20
insert into student values (1,"张三",20);
# 3)    再次向该表插入数据:#      编号:2     姓名:李四  
insert into student(sid,sname) values (2,"李四");
# 4)    批量向该表插入三条数据
insert into student(sname,age) values ("王五",43),("赵六",34),("郑七",30);
# 5) 修改张三的年龄为23。
update student set age = 23 where sname = "张三";
# 6)    修改编号为2的学生年龄为25。
update student set age = 25 where sid = 2;
# 7)    删除id为5的用户的信息。
delete from student where sid = 5;
# 1)    在emp表中,查询所有的员工信息。
select * from emp;
# 2)    在emp表中,查询所有员工的员工编号,员工姓名。
select empno, ename from emp;
# 3)    在emp表中,查询所有工龄大于35年的员工信息。
SELECT * from emp where TIMESTAMPDIFF(YEAR,emp.hiredate, DATE_FORMAT(now(), '%Y-%m-%d')) > 35;
alter table emp add work_years int after hiredate;
update emp set work_years = TIMESTAMPDIFF(YEAR,emp.hiredate, DATE_FORMAT(now(), '%Y-%m-%d'));
select * from emp where work_years > 35;
# 4)    在emp表中,查询员工工资在2000到3000的员工信息。
select * from emp where sal between 2000 and 3000;
# 5)    在emp表中,为所有奖金<100的员工将奖金提升100元。
update emp set comm = 100 where comm < 100 or comm is null;
# 6)    在emp表中,查询所有的职位信息,不能有重复。
select distinct job from emp;
# 7)    在emp表中,查询所有姓名中包含S的员工信息。
select * from emp where ename like "%S%";
# 8)    在emp表中,查询所有员工中工资最低的三个员工的信息。
# sal升序排序
select * from emp order by sal ;
# 选取前三名
select * from emp order by sal limit 3;
# 9)    在emp表中,查询30号部门的平均工资。
select AVG(sal) from emp where deptno = 30;
# 10)    在emp表中,查询平均工资大于2000的部门编号和平均工资。
select distinct deptno from emp;
select AVG(sal) > 2000, deptno from emp GROUP BY deptno;
# 11)    在emp表中,查询超过1000元的各个部门的部门编号和平均工资。
select AVG(sal) > 1000, deptno from emp GROUP BY deptno;
# 12)    在emp表中,查询入职年份超过35年的员工信息。
SELECT * from emp where TIMESTAMPDIFF(YEAR, emp.hiredate, DATE_FORMAT(now(), '%Y-%m-%d')) > 35;
select * from emp where work_years >35;
# 13)    在emp表中, 查询在该月月底前两天入职的员工信息。
select * from emp where date_format(emp.hiredate,"%d")>= 28;