1. 查询出部门编号为30的所有员工
SELECT * FROM emp WHERE deptno = 30
2. 查询所有销售员的姓名,编号和部门编号
SELECT ename, empno, deptno FROM emp WHERE job = '销售员'
3. 找出奖金高于工资的员工
SELECT * FROM emp WHERE COMM > sal
4.找出奖金高于工资60%的员工
SELECT * FROM emp WHERE COMM > (sal * 0.6)
5. 找出部门编号为10中的所有经理,和部门编号为20中的所有销售员的详细资料
SELECT * FROM emp WHERE (deptno = 10 AND job = '经理') OR (deptno = 20 AND job = '销售员')
6. 找出部门编号为10中所有经理,部门编号为20中所有销售员,还有既不是经理又不是销售员但工资大于或等于20000的所有员工详细资料
SELECT * FROM emp
WHERE (deptno = 10 AND job = '经理')
OR (deptno = 20 AND job = '销售员')
OR (job NOT IN('经理','销售员') AND sal >= 20000)
7.找出所有有奖金的工种
SELECT DISTINCT job FROM emp WHERE COMM IS NOT NULL
8. 找出无奖金或奖金低于1000的员工
SELECT * FROM emp WHERE COMM IS NULL OR COMM < 1000
9. 查询名字由3个字组成的员工
SELECT * FROM emp WHERE ename LIKE '___'
10. 查询2000年入职的员工
SELECT * FROM emp WHERE hiredate LIKE '2000%'
SELECT * FROM emp WHERE YEAR(hiredate) = '2000'
11.查询所有员工详细信息,并以编号升序排序
SELECT * FROM emp ORDER BY empno ASC
12. 查询所有员工详细信息,用工资降序排序,如果工资相同使用入职时间升序排序
SELECT * FROM emp ORDER BY sal DESC, hiredate ASC
13. 查询每个部门的平均工资
SELECT deptno, AVG(sal) FROM emp GROUP BY deptno
14.查询每个部门的雇员数量
SELECT deptno, COUNT(*) FROM emp GROUP BY deptno
15. 查询每种工作的最高工资,最低工作、人数
SELECT job AS '工作', MAX(sal) AS '最高工资', MIN(sal) AS '最低工资', COUNT(*) AS '人数' FROM emp GROUP BY job
16.显示非销售人员工作名称以及从事同一工作雇员的月工资总和,并且要满足从事同一工作的雇员的月工资合计大于50000,输出结果按月工作的合计升序排列
SELECT job, SUM(sal) FROM emp
WHERE job != '销售员'
GROUP BY job
HAVING SUM(sal) > 50000
ORDER BY SUM(sal) ASC
网友评论