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表中,查询员工工资在2000到3000的员工信息。
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;