按照下图使用语句创建出来,并按照以下要求完成操作
图
建表代码:
USE java0723;
CREATE TABLE emp1(
empno INT,
ename VARCHAR(10),
job VARCHAR(10),
mgr INT,
hiredate DATE,
sal FLOAT(7,2),
COMM FLOAT(7,2),
deptno INT
);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1001,'甘宁','文员',1013,'2000-12-17',8000,20);
INSERT INTO emp1 VALUES(1002,'黛绮丝','销售员',1006,'2001-02-20',16000,3000,30);
DELETE FROM emp1 WHERE empno='1002'
INSERT INTO emp1 VALUES(1003,'殷天正','销售员',1006,'2001-02-22',12500,5000,30);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1004,'刘备','经理',1009,'2001-04-02',29750,20);
INSERT INTO emp1 VALUES(1005,'谢逊','销售员',1006,'2001-09-28',12500,14000,30);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1006,'关羽','经理',1009,'2001-05-01',28500,30);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1007,'张飞','经理',1009,'2001-09-01',24500,10);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1008,'诸葛亮','分析师',1004,'2007-04-19',30000,20);
INSERT INTO emp1(empno,ename,job,hiredate,sal,deptno) VALUES(1009,'曾阿牛','董事长','2001-11-17',50000,10);
INSERT INTO emp1 VALUES(1010,'韦一笑','销售员',1006,'2001-09-08',15000,0,30);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1011,'周泰','文员',1008,'2007-05-23',11000,20);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1012,'程普','文员',1008,'2001-12-03',9500,30);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1013,'庞统','分析师',1004,'2001-12-03',30000,20);
INSERT INTO emp1(empno,ename,job,mgr,hiredate,sal,deptno) VALUES(1014,'黄盖','文员',1008,'2002-01-23',13000,10);
INSERT INTO emp1 VALUES(1015,'张三','保洁员',1001,'2013-05-01',80000,50000,50);
SELECT * FROM emp1;
查询如图所示:
操作要求
1. 查询出部门编号为30的所有员工
SELECT ename,deptno FROM emp1 WHERE deptno='30';
2. 所有销售员的姓名、编号和部门编号。
SELECT empno,ename,deptno FROM emp1;
3.找出奖金高于工资的员工。
SELECT ename FROM emp1 WHERE COMM>sal;
4.找出奖金高于工资的60%的员工。
SELECT ename FROM emp1 WHERE COMM > sal*0.6;
5.找出部门编号为10中所有经理,和部门编号为20中所有销售员的详细资料。
SELECT * FROM emp1 WHERE (deptno='10'AND job='经理')OR (deptno='20'AND job='销售员');
6. 找出部门编号为10中所有经理,部门编号为20中所有销售员,还有即不是经理又不是销售员但其工资大或等于20000的所有员工详细资料。
SELECT * FROM emp1 WHERE (deptno='10'AND job='经理')OR (deptno='20'AND job='销售员')
OR (job<>'经理'AND job<>'销售员' AND sal>=20000);
7. 无奖金或奖金低于1000的员工。
SELECT ename FROM emp1 WHERE COMM IS NULL OR COMM < 1000;
8. 查询名字由三个字组成的员工
SELECT ename FROM emp1 WHERE ename LIKE '___';
9.查询2000年入职的员工。
SELECT ename FROM emp1 WHERE hiredate LIKE '2000%'
10. 查询所有员工详细信息,用编号升序排序
SELECT * FROM emp1 ORDER BY empno;
11. 查询所有员工详细信息,用工资降序排序,如果工资相同使用入职日期升序排序
SELECT * FROM emp1 ORDER BY sal DESC,hiredate ASC;
12. 查询姓周的两个名字的员工。
SELECT ename FROM emp1 WHERE ename LIKE '周_';
13. 查询所有姓张的员工。
SELECT ename FROM emp1 WHERE ename LIKE '张';
14. 查询该公司有多少个岗位,每个岗位有多少人。
SELECT COUNT(*)AS '职位'FROM emp1;
SELECT job,COUNT(*) FROM emp1 GROUP BY job;
15.查询哪个岗位中人数大于3。
SELECT job,COUNT(*) FROM emp1 GROUP BY job HAVING COUNT(*)>3;