MYSQL晚作业1

emp表
dept表

 		1)	在emp表中,查询所有的员工信息。
    	select *from emp;
    	2)	在emp表中,查询所有员工的员工编号,员工姓名。
    	select empno,ename from emp;
    	3)	在emp表中,查询所有工龄大于35年的员工信息。
    	select *,concat(year(now())-year(hiredate)) hireyear from emp having hireyear>35;
    	4)	在emp表中,查询员工工资在20003000的员工信息。
    	select *from emp where sal BETWEEN 2000 and 3000;
    	5)	在emp表中,为所有奖金<100的员工将奖金提升100元。
    	select comm+100 addcomm from emp where comm<100;
    	6)	在emp表中,查询所有的职位信息,不能有重复。
    	select distinct job from emp;
    	7)	在emp表中,查询所有姓名中包含S的员工信息。
    	select *from emp where ename like'%s%';
    	8)	在emp表中,查询所有员工中工资最低的三个员工的信息。
    	select *from emp ORDER BY sal asc limit 3;
    	9)	在emp表中,查询30号部门的平均工资。
    	select avg(sal) from emp where deptno=30;
    	10)	在emp表中,查询平均工资大于2000的部门编号和平均工资。
    	select deptno,avg(sal) avgsal from emp group by deptno having avgsal>2000;
    	11)	在emp表中,查询超过1000元的各个部门的部门编号和平均工资。
    	select deptno,avg(sal) avgsal from emp where sal>1000 group by deptno ;
    	12)	在emp表中,查询入职年份超过35年的员工信息。
    	select *,concat(year(now())-year(hiredate)) hireyear from emp having hireyear>35;
    	13)	在emp表中, 查询在该月月底前两天入职的员工信息。
    	select *,concat(day(last_day(hiredate))-day(hiredate)) lastday from emp having lastday=2;

在这里插入图片描述

create table news(
	newsID int primary key auto_increment,
	newsTitle varchar(50),
	editer varchar(50),
	upDateTime Date,
	content varchar(500)
);
insert into news values(null,'蔡徐坤打篮球','亿万粉丝',now(),'帅就完事了'),(null,'马云不爱钱','亿万粉丝',now(),'牛就完事了');
insert into news(newsTitle,editer,upDateTime,content) values('第一','chx','2018-07-18','体育'),('最编程','李玲','2017-5-18','Java');
#删除所有不是今年的新闻
delete from news where year(now())-year(upDateTime)=0;
select *from news order by upDateTime desc;
select *from news where content='Java' and editer='李玲';
select *from news where newsTitle like '%第一%' or newsTitle  like '%最%';
drop table news;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Carl·杰尼龟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值