当前位置:   article > 正文

SQL语句,查询操作_sql 将最高工资的人和最低工资的人 查询出来

sql 将最高工资的人和最低工资的人 查询出来
  1. #查询所有员工的姓名
  2. SELECT ename FROM emp;
  3. #查询员工的薪水和姓名
  4. SELECT ename , sal FROM emp;
  5. #查询员工表所有数据
  6. SELECT * FROM emp;
  7. #查询每一个员工的年薪
  8. SELECT ename , sal*12 AS yearSal FROM emp;
  9. #查询薪资为5000的员工的信息
  10. SELECT * FROM emp
  11. WHERE sal = 5000;
  12. #查询职位为MANAGER的员工的信息
  13. SELECT * FROM emp
  14. WHERE job = "MANAGER";
  15. #查询薪资不是5000的员工的信息
  16. SELECT * FROM emp
  17. WHERE sal != 5000;
  18. #查询职位不是MANAGER的员工的信息
  19. SELECT * FROM emp
  20. WHERE job != "MANAGER";
  21. #查询薪资大于2000的员工的信息
  22. SELECT * FROM emp
  23. WHERE sal > 2000;
  24. #查询薪资在10002000之间的员工的信息
  25. SELECT * FROM emp
  26. WHERE sal >= 1000 && sal <=2000;
  27. #查询部门编号为2030的部门的信息
  28. SELECT * FROM dept
  29. WHERE deptno = 20 or deptno = 30;
  30. #查询部门编号为2030的部门的信息
  31. SELECT * FROM dept
  32. WHERE deptno = 20 or deptno = 30;
  33. #查询部门编号不是2030的部门的信息
  34. SELECT * FROM dept
  35. WHERE deptno != 20 AND deptno != 30;
  36. #查询没有补助的员工的信息
  37. SELECT * FROM emp
  38. WHERE comn IS NULL;
  39. #查有补助的员工的信息
  40. SELECT * FROM emp
  41. WHERE comn != "";
  42. #查询姓名中第一个字母带有s的员工的信息
  43. SELECT * FROM emp
  44. WHERE ename LIKE "S%";
  45. #查询姓名中第二个字母带有m的员工的信息
  46. SELECT * FROM emp
  47. WHERE ename LIKE "_M%";
  48. #查询姓名中带有字母m的员工的信息
  49. SELECT * FROM emp
  50. WHERE ename LIKE "%M%";
  51. #查询员工信息并根据员工的薪水(升序)
  52. SELECT * FROM emp
  53. ORDER BY sal ASC;
  54. #查询员工信息并根据员工的薪水(降序)
  55. SELECT * FROM emp
  56. ORDER BY sal DESC;
  57. #查询员工信息并根据员工入职日期降序排列
  58. SELECT * FROM emp
  59. ORDER BY hiredate DESC;
  60. #查询职位为MANAGER 的员工信息,并且按照薪资从高到低排序
  61. SELECT * FROM emp
  62. WHERE job = "MANAGER"
  63. ORDER BY sal DESC;
  64. #查询员工的最高工资
  65. SELECT MAX(sal) AS "员工的最高工资" FROM emp;
  66. #查询员工的最低工资
  67. SELECT MIN(sal) AS "员工的最低工资" FROM emp;
  68. #查询当前公司总员工数
  69. SELECT COUNT(emno) AS "公司总员工数" FROM emp;
  70. #查询所有员工的年支出
  71. SELECT SUM(sal) AS "所有员工的年支出" FROM emp;
  72. #查询员工平均工资-->有问题
  73. SELECT AVG(sal) AS "员工平均工资" FROM emp;
  74. #通过员工表查询公司有哪几个部门-->有问题
  75. SELECT DISTINCT deptno AS "部门编号" FROM emp;
  76. #查询每种工作的最高薪资
  77. SELECT job,sal AS "maxSal" FROM emp
  78. GROUP BY job
  79. HAVING MAX(sal);
  80. #查询每种工作的最高薪资并升序显示
  81. SELECT job,sal AS "maxSal" FROM emp
  82. GROUP BY job
  83. HAVING MAX(sal)
  84. ORDER BY sal ASC;
  85. #查询每个部门的平均薪资
  86. SELECT deptno,sal AS "平均工资" FROM emp
  87. GROUP BY deptno
  88. HAVING AVG(sal);
  89. #查询平均工资大于2000的岗位的平均工资 -->有问题
  90. SELECT job,sal AS "平均工资" FROM emp
  91. GROUP BY deptno
  92. HAVING AVG(sal)>=2000;
  93. #查询当前员工中工资排在前三位的人的信息
  94. SELECT * FROM emp
  95. ORDER BY sal DESC
  96. LIMIT 3;
  97. #查询员工表数据并进行分页,每页显示5条数据,查看第一页的数据
  98. #找出薪水比公司平均薪水高的员工,要求显示员工的名字和薪水 --->有问题
  99. SELECT ename,sal FROM emp
  100. GROUP BY ename
  101. HAVING sal>AVG(sal);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/615187
推荐阅读
相关标签
  

闽ICP备14008679号