use mydb2; CREATE TABLE emp( empno INT, ename VARCHAR(50), job VARCHAR(50), mgr INT, hiredate DATE, sal INT, comm INT, deptno INT ); INSERT INTO emp VALUES(7369,'SMITH','CLERK',7902, '1980-12-17',800,NULL,20); INSERT INTO emp VALUES(7499,'ALLEN','SALESMAN',7698,' 1981-02-20',1600,300,30); INSERT INTO emp VALUES(7521,'WARD','SALESMAN',7698,'1981-02-22',1250,500,30); INSERT INTO emp VALUES(7566,'JONES','MANAGER',7839,'1981-04-02',2975,NULL,20); INSERT INTO emp VALUES(7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30); INSERT INTO emp VALUES(7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,NULL,30); INSERT INTO emp VALUES(7782,'CLARK','MANAGER',7839,'1981-06-09',2450,NULL,10); INSERT INTO emp VALUES(7788,'SCOTT','ANALYST',7566,'1987-04-19',3000, NULL,20); INSERT INTO emp VALUES(7839,'KING','PRESIDENT',NULL,'1981-11-17',5000,NULL,10); INSERT INTO emp VALUES(7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,0,30); INSERT INTO emp VALUES(7876,'ADAMS','CLERK',7788,'1987-05-23',1100,NULL,20); INSERT INTO emp VALUES(7900,'JAMES','CLERK',7698,'1981-12-03',950,NULL,30); INSERT INTO emp VALUES(7902,'FORD','ANALYST',7566,'1981-12-03',3000,NULL,20); INSERT INTO emp VALUES(7934,'MILLER','CLERK',7782,'1982-01-23',1300,NULL,10); -- 6、求平均薪水大于2000的部门]编号 -- 7、将部门平均薪水大于1500的部门]编号列出来,按部门平均薪水降序排列I -- 8、选择公司中有奖金的员工姓名,工资 -- 9、查询员工最高工资和最低工资的差距
时间: 2023-06-09 11:06:25 浏览: 112
CreateTable.rar_create table ja_createTab_createTable
我理解了你的问题,以下是答案:
6、求平均薪水大于2000的部门编号:
SELECT deptno FROM emp GROUP BY deptno HAVING AVG(sal) > 2000;
7、将部门平均薪水大于1500的部门编号列出来,按部门平均薪水降序排列:
SELECT deptno, AVG(sal) AS avg_sal FROM emp GROUP BY deptno HAVING AVG(sal) > 1500 ORDER BY avg_sal DESC;
8、选择公司中有奖金的员工姓名、工资:
SELECT ename, sal FROM emp WHERE comm IS NOT NULL;
9、查询员工最高工资和最低工资的差距:
SELECT MAX(sal) - MIN(sal) AS diff_sal FROM emp;
阅读全文